Forum: Ruby-Forum.com url_for not working

3548d30217e9921c410db19ce8ce38d0?d=identicon&s=25 Sunny Bogawat (sunny_bogawat)
on 2008-09-17 10:08
Hi,
  I am using 'url_for' for constructing url in my model but it gives me
error
  <NoMethodError: undefined method `url_for' for Xyz:Class>
   how to access url_for in model and it possible to call controller
method in
   model and how to call it?


  Please urgently give reply?
B53e74f9b64608439e4da7b0c8914f27?d=identicon&s=25 Daniel Tooop (danieltooop)
on 2009-02-03 00:09
Sunny Bogawat wrote:
> Hi,
>   I am using 'url_for' for constructing url in my model but it gives me
> error
>   <NoMethodError: undefined method `url_for' for Xyz:Class>
>    how to access url_for in model and it possible to call controller
> method in
>    model and how to call it?
>
>
>   Please urgently give reply?


Hi hope this code will help you, this is the code i used and it has
worked for me. So, please see to it.

def index
redirect_to :action=> 'view', :name => 'Home'
end

def view
@name = params[:name]
@page = Page.find_by_name(@name)
end

def edit
@name = params[:name]
@page = Page.find_by_name(@name)
end

def save
 @content = params[:content]
 @name = params[:name]
 @page = Page.find_by_name(@name)

 if !@page
   @page = Page.create(:name => @name)
 end

 Revision.create(:page => @page, :content => @content)

 redirect_to :action => :view, :name => @name
end

With Regards,
http://www.southcoastrecovery.com - Daniel
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.