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.

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

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

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

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