Sharing session variables across Controllers?

I have a couple of session parameters set in a Controller which I want
to
use in a different Controller. Which is the cleanest way to do this?

I did quite a bit of Googling but could not come up with anything
substancial.

Session variables should be shared, unless I’m not understanding the
question.

You can set a session variable in one controller like so:

session[:my_key] = ‘my value’

Then access it in another controller by simply calling session[:my_key]

In my application once I call an action on a different controller all my
session variables seem to disappear also the login session seems to
expire.
Even if I start a new request from browser I need to authenticate
again.

On 8 March 2012 15:06, Myth17 [email protected] wrote:

In my application once I call an action on a different controller all my
session variables seem to disappear also the login session seems to expire.
Even if I start a new request from browser I need to authenticate again.

Something is clearing the session then. Do a global search in the
code for session and see if you clear it anywhere. If you find it
cleared anywhere, even if you think that code should not be called,
then put some debug in to check (or just comment out the clear for
temporarily).

Colin

[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

I can see message “WARNING: Can’t verify CSRF token authenticity” on the
rails console. Could this be the reason?

On 8 March 2012 15:53, Myth17 [email protected] wrote:

I can see message “WARNING: Can’t verify CSRF token authenticity” on the
rails console. Could this be the reason?

Yes, probably. Rails is clearing the session because it detects the
problem. Google for the message and you will find lots of hits.

Colin

In my application once I call an action on a different controller all
temporarily).

You can set a session variable in one controller like so:
To view this discussion on the web visit

http://groups.google.com/group/rubyonrails-talk?hl=en.

gplus.to/clanlaw

Its actually weird then, I did a search to double check but I am not
clearing the session anywhere. :expressionless: