[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rials varable becomes nill on a render.

Harris Reynolds

2/15/2007 4:57:00 PM

This happens because you are calling the render method instead of redirect_to. Calling render causes the invocation to "render" the new view and the new action (method) is never invoked. If you change that to redirect_to it will call the action you want.The net/net is the... render basically passed control to the view, redirect_to passes control to the actual action method.hope that helps,~harris>First off apologies for a rails question on the ruby list, but the >rails mailing list sign-on page seems to be down at the moment so I >thought I would look for help here.Bearing in mind I am very new to Rails... I have a create action:def create @post = Post.new(params[:post]) if @post.save @post.tag_with(params[:tag_list]) flash[:notice] = 'Post was successfully created.' redirect_to :action => 'list' else @tag_list = params[:tag_list] render :action => 'new' end endif the @post.save returns false the user is presented with the new view again:def new @tags = Tag.find(:all) @post = Post.new endOn the initial call to new the new view displays a list of tags from the array @tags. If the create action fails and the render :action => 'new' line is executed the @tags variable becomes nillHow come this happens? and is there a 'clean' was of keeping the @tags variable as it should be no matter how many times the create action fails??Any help will be gratefully received.David. ____________________________________________________________________________________The fish are biting. Get more visitors on your site using Yahoo! Search Marketing.http://searchmarketing.yahoo.com/arp/sponsoredsea...

1 Answer

David Madden

2/15/2007 5:30:00 PM

0

Thank you.

On 15 Feb 2007, at 16:57, Harris Reynolds wrote:

> This happens because you are calling the render method instead of
> redirect_to. Calling render causes the invocation to "render" the
> new view and the new action (method) is never invoked. If you
> change that to redirect_to it will call the action you want.
>
> The net/net is the... render basically passed control to the view,
> redirect_to passes control to the actual action method.
>
> hope that helps,
>
> ~harris
>
>
>> First off apologies for a rails question on the ruby list, but the
>> rails mailing list sign-on page seems to be down at the moment so I
>> thought I would look for help here.
>
> Bearing in mind I am very new to Rails... I have a create action:
>
> def create
> @post = Post.new(params[:post])
> if @post.save
> @post.tag_with(params[:tag_list])
> flash[:notice] = 'Post was successfully created.'
> redirect_to :action => 'list'
> else
> @tag_list = params[:tag_list]
> render :action => 'new'
> end
> end
>
> if the @post.save returns false the user is presented with the new
> view again:
>
> def new
> @tags = Tag.find(:all)
> @post = Post.new
> end
>
> On the initial call to new the new view displays a list of tags from
> the array @tags. If the create action fails and the render :action =>
> 'new' line is executed the @tags variable becomes nill
>
> How come this happens? and is there a 'clean' was of keeping the
> @tags variable as it should be no matter how many times the create
> action fails??
>
> Any help will be gratefully received.
>
> David.
>
>
>
> ______________________________________________________________________
> ______________
> The fish are biting.
> Get more visitors on your site using Yahoo! Search Marketing.
> http://searchmarketing.yahoo.com/arp/sponsoredsea...
>