# Action Variables Not Available In The View For A Specific Ac

**URL:** <https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159>\
**Category:** Rails\
**Created:** [May 10, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159 "2006-05-10T19:33:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [May 10, 2006, 7:33pm UTC](https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159/1 "2006-05-10T19:33:08Z")

</div>

I am setting an action variable in my PagesController such as:

def manage  
render(:layout =\> “admin”)  
@strOut = “STRING Variable Set From The MANAGE Action!”  
end

And in the /views/pages/manage.rhtml view, I don?t have access to that  
@strOut variable by trying to call it as: \<%= @strOut %\>

However, I am setting the same variable in another action in the  
controller  
such as:

def view  
@strOut = “STRING Variable Set From The EDIT Action!”  
end

… and I have full access to it in /views/pages/view.rhtml

The only difference in the actions being this:  
render(:layout =\> “admin”) …in the manage action.

So, I want the manage action to use /views/layouts/admin.rhtml, and the  
edit  
action to use /views/layouts/pages.rhtml.

I’m not sure if the layouts have anything to do with it but I really  
don’t  
know why that variable cannot be called from the view.

–

Jeff

---

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [May 10, 2006, 8:09pm UTC](https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159/2 "2006-05-10T20:09:53Z")

</div>

It’s an order thing.

render :layout =\> ‘admin’ actually copies the instance variables from  
the controller for use in the template. It’s actually a bit more  
complicated than that but that’s the just. In otherwards, at the time  
the instance variables are copied to the template, your instance  
variable @strOut does not exist and is not copied. Just code your  
method like:

def manage  
@strOut = “BLAH”  
render :action =\> ‘admin’  
end

and all should be good.

-Matt

---

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [May 10, 2006, 8:14pm UTC](https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159/3 "2006-05-10T20:14:43Z")

</div>

Excellent, re-ordering them worked. Thanks very much.

–

Jeff

---

<div class="post-metadata">

**Author:** ![jwigal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6a8cbe/32.png) [@jwigal](https://www.ruby-forum.com/u/jwigal)\
**Post date:** [May 10, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/action-variables-not-available-in-the-view-for-a-specific-ac/60159/4 "2006-05-10T20:45:32Z")

</div>

On May 10, 2006, at 10:31 AM, Jeff W. wrote:

> I am setting an action variable in my PagesController such as:
> 
> def manage  
> render(:layout =\> “admin”)  
> @strOut = “STRING Variable Set From The MANAGE Action!”  
> end
> 
> And in the /views/pages/manage.rhtml view, I don?t have access to that  
> @strOut variable by trying to call it as: \<%= @strOut %\>

You set the variable after the view was rendered. Swap those two lines.

jeremy
