# Rials varable becomes nill on a render

**URL:** <https://www.ruby-forum.com/t/rials-varable-becomes-nill-on-a-render/85706>\
**Category:** Ruby\
**Created:** [February 15, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/rials-varable-becomes-nill-on-a-render/85706 "2007-02-15T17:57:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harris\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/53a042/32.png) [@Harris\_R](https://www.ruby-forum.com/u/Harris_R)\
**Post date:** [February 15, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/rials-varable-becomes-nill-on-a-render/85706/1 "2007-02-15T17:57:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Harris\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/53a042/32.png) [@Harris\_R](https://www.ruby-forum.com/u/Harris_R)\
**Post date:** [February 15, 2007, 6:30pm UTC](https://www.ruby-forum.com/t/rials-varable-becomes-nill-on-a-render/85706/2 "2007-02-15T18:30:42Z")

</div>

Thank you.
