Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long do objects stored in Rails' sessions persist?

If I do session[:greeting] = "Hi!" in one controller action, for how long will I be able to refer to session[:greeting] in other controller actions?

Until the user closes his browser?

Until a certain amount of time passes?

Also, how can I configure this value?

like image 778
Tom Lehman Avatar asked Sep 21 '09 03:09

Tom Lehman


2 Answers

Until the user closes her browser. That's the definition of a session.

To configure something longer, you will need to use one of:

  • cookies. These can be marked to stay for any period of time (or until the user closes the browser)
  • have the user log in

Often there's a combination of these, where the user is given a "remember me" token as a cookie, so that they don't have to log in every time they restart the browser.

like image 171
ndp Avatar answered Oct 29 '22 09:10

ndp


It is available until the user closes their browser.

like image 39
Garrett Avatar answered Oct 29 '22 08:10

Garrett