# Passing data between controller methods

**URL:** <https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905>\
**Category:** Rails\
**Created:** [July 20, 2007, 2:33am UTC](https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905 "2007-07-20T02:33:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 20, 2007, 2:33am UTC](https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905/1 "2007-07-20T02:33:20Z")

</div>

Hi All

What is the best way to pass data between different controller methods  
in support of different views?

Thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 23, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905/2 "2007-07-23T14:44:39Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hi All
> 
> What is the best way to pass data between different controller methods  
> in support of different views?
> 
> Thanks

I am trying to do the same but it looks like every controller gets its  
own session, so variables can’t be exchanged via session[].

It looks like rails feature.

Has anyone been dealing with the same problem.

by  
TheR

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 23, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905/3 "2007-07-23T14:49:30Z")

</div>

Could you please explain what you mean by “passing data”? Do you mean  
calling other methods in a controller or do you mean keeping information  
around through different requests.

If you mean the latter, then your session is the way to go if that  
information is not fit to be in the database.

Damjan, could you expound on your response? Controllers do not get their  
own  
session. The session is the construct built to keep information around  
for  
the entire time a user is using your site.

Jason

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 23, 2007, 9:52pm UTC](https://www.ruby-forum.com/t/passing-data-between-controller-methods/109905/4 "2007-07-23T21:52:23Z")

</div>

Jason R. wrote:

> Could you please explain what you mean by “passing data”? Do you mean  
> calling other methods in a controller or do you mean keeping information  
> around through different requests.
> 
> If you mean the latter, then your session is the way to go if that  
> information is not fit to be in the database.
> 
> Damjan, could you expound on your response? Controllers do not get their  
> own  
> session. The session is the construct built to keep information around  
> for  
> the entire time a user is using your site.
> 
> Jason

I was playing with Ajax today and got this strange behaviour. If the  
Ajax called method was in the same controller class, then Ajax call had  
the same session ID (cleary seen in Mongrel). If the Ajax response  
method was in another controller class, the call got different session  
ID an thus proper session[] could not be reached in caller method.

I was testing loading some Ajax data on page load and it made me crazy  
for over an hour until I changed the program and call Ajax method within  
same controller.

by  
TheR
