Forum: Ruby Rials varable becomes nill on a render.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D030415ddde3289040ff66e88853716c?d=identicon&s=25 Harris Reynolds (Guest)
on 2007-02-15 17:57
(Received via mailing list)
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,


>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])
       flash[:notice] = 'Post was successfully created.'
       redirect_to :action => 'list'
       @tag_list = params[:tag_list]
       render :action => 'new'

if the returns false the user is presented with the new
view again:

def new
     @tags = Tag.find(:all)
     @post =

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.

5ef95bf95af5064ff3c2bcafa6a8a212?d=identicon&s=25 David Madden (Guest)
on 2007-02-15 18:30
(Received via mailing list)
Thank you.
This topic is locked and can not be replied to.