# instance variable in controller -\> views with RJS?

**URL:** <https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082>\
**Category:** rubyonrails-talk\
**Created:** [April 16, 2008, 4:46am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082 "2008-04-16T04:46:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 16, 2008, 4:46am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/1 "2008-04-16T04:46:02Z")

</div>

Hi everyone,

This should be pretty simple... If you have an instance variable in a controller passed to its view, and you have \<% form\_remote\_tag :url =\> { :action =\> 'other\_action' } do -%\> etc \<% end %\>, can you access the instance variable in the action other\_action?

You're not really changing the view...

The idea is that I really need to store a variable and have it go from first action -\> view -\> second action -\> manipulated -\> passed back to the view in render :update. If the above is not possible, what is the best way to do this? Sessions?

Thanks. - Shannon

---

<div class="post-metadata">

**Author:** ![OhMyRuby](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@OhMyRuby](https://discuss.rubyonrails.org/u/OhMyRuby)\
**Post date:** [April 16, 2008, 5:25am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/2 "2008-04-16T05:25:29Z")

</div>

i am new to ruby but i believe you can do it with the local option on partial.

---

<div class="post-metadata">

**Author:** ![Julian\_Leviston](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Julian\_Leviston](https://discuss.rubyonrails.org/u/Julian_Leviston)\
**Post date:** [April 16, 2008, 5:30am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/3 "2008-04-16T05:30:54Z")

</div>

pass it in on the form

\<% form\_remote\_tag :url =\> {:action =\> 'other\_action', :the\_var =\>  
@the\_var } do -%\> then in the destination action, set

@the\_var = params[:the\_var]

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #4 coming soon! [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![Julian\_Leviston](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Julian\_Leviston](https://discuss.rubyonrails.org/u/Julian_Leviston)\
**Post date:** [April 16, 2008, 5:31am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/4 "2008-04-16T05:31:14Z")

</div>

No, that's not what he meant.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #4 coming soon! [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 16, 2008, 6:05am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/5 "2008-04-16T06:05:21Z")

</div>

Alright. But you can't access it directly from the second action right? The variable I want to pass is a very long array of objects, and I was afraid it wasn't going to be efficient if I passed it through a form (or a session).

Julian Leviston wrote:

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 16, 2008, 6:22am UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/6 "2008-04-16T06:22:13Z")

</div>

Shannon Clipt wrote:

> Alright. But you can't access it directly from the second action right? The variable I want to pass is a very long array of objects, and I was afraid it wasn't going to be efficient if I passed it through a form (or a session).
> 
> Julian Leviston wrote:
> 
> > pass it in on the form
> > 
> > \<% form\_remote\_tag :url =\> {:action =\> 'other\_action', :the\_var =\> @the\_var } do -%\> then in the destination action, set
> > 
> > @the\_var = params[:the\_var]
> > 
> > Julian.
> > 
> > Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #4 coming soon! [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

When you submit that form it will make a 'new' request back to the server. Unfortunately rails really resets 'per request' -- except for session vars and things you pass back to it.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 16, 2008, 3:46pm UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/7 "2008-04-16T15:46:03Z")

</div>

Shannon Clipt wrote:

> by the way, the object i'm passing has sensitive data. should i still pass it through the form?

only if you trust the security of your clients' computers 🙂I suppose if it's sensitive save it to your session [or to a database then reload it]

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 16, 2008, 3:53pm UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/8 "2008-04-16T15:53:17Z")

</div>

> Shannon Clipt wrote:
> 
> > by the way, the object i'm passing has sensitive data. should i still pass it through the form?
> 
> only if you trust the security of your clients' computers 🙂I suppose if it's sensitive save it to your session [or to a database then reload it]

bearing in mind of course that with the default session store the  
session data is on the client's computer.

Fred

---

<div class="post-metadata">

**Author:** ![Phillip\_Gawlowski](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@Phillip\_Gawlowski](https://discuss.rubyonrails.org/u/Phillip_Gawlowski)\
**Post date:** [April 16, 2008, 4:05pm UTC](https://discuss.rubyonrails.org/t/instance-variable-in-controller-views-with-rjs/28082/9 "2008-04-16T16:05:58Z")

</div>

Frederick Cheung wrote:

> > Shannon Clipt wrote:
> > 
> > > by the way, the object i'm passing has sensitive data. should i still pass it through the form?
> > 
> > only if you trust the security of your clients' computers 🙂I suppose if it's sensitive save it to your session [or to a database then reload it]
> 
> bearing in mind of course that with the default session store the session data is on the client's computer.

And keeping in mind that SSL should be used to encrypt transmitting sensitive information over a hostile network like the internet.

- -- Phillip Gawlowski Twitter: twitter.com/cynicalryan

At the bottom of a good deal of the bravery that appears in the world there lurks a miserable cowardice. Men will face powder and steel because they cannot face public opinion. ~ -- Edwin Hubbel Chapin
