Rials varable becomes nill on a render.

H

Harris Reynolds

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.=0A=0AThe net/net is the... render basically=
passed control to the view, redirect_to passes control to the actual actio=
n method.=0A=0Ahope that helps,=0A=0A~harris=0A=0A=0A>First off apologies f=
or a rails question on the ruby list, but the =0A>rails mailing list sign-=
on page seems to be down at the moment so I =0A>thought I would look for h=
elp here.=0A=0ABearing in mind I am very new to Rails... I have a create ac=
tion:=0A=0Adef create=0A @post =3D Post.new(params[:post])=0A if @p=
ost.save=0A @post.tag_with(params[:tag_list])=0A flash[:notice]=
=3D 'Post was successfully created.'=0A redirect_to :action =3D> 'li=
st'=0A else=0A @tag_list =3D params[:tag_list]=0A render :a=
ction =3D> 'new'=0A end=0A end=0A=0Aif the @post.save returns false t=
he user is presented with the new =0Aview again:=0A=0Adef new=0A @tags=
=3D Tag.find:)all)=0A @post =3D Post.new=0A end=0A=0AOn the initial =
call to new the new view displays a list of tags from =0Athe array @tags. =
If the create action fails and the render :action =3D> =0A'new' line is ex=
ecuted the @tags variable becomes nill=0A=0AHow come this happens? and is t=
here a 'clean' was of keeping the =0A@tags variable as it should be no mat=
ter how many times the create =0Aaction fails??=0A=0AAny help will be grat=
efully received.=0A=0ADavid.=0A=0A=0A =0A__________________________________=
__________________________________________________=0AThe fish are biting. =
=0AGet more visitors on your site using Yahoo! Search Marketing.=0Ahttp://s=
earchmarketing.yahoo.com/arp/sponsoredsearch_v2.php
 
D

David Madden

Thank you.

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/sponsoredsearch_v2.php
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top