Can you please provide a simple example, as I am a noob in rails.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A session is a dialog between the server and the client; that dialog consists of one or more requests and responses.
Rails stores a bundle of variables for each session, so that you can have per-user state that persists between requests. To access the session in your controller, use the method
session. It behaves like a hash, except that it is automatically persisted between requests. If you store something in the session during one request:Then you can get it back in a later request:
The session store is most often (but not exclusively) used for authentication. If you are using an authentication gem such as devise, it uses the session store to keep track of who’s logged in.
The session store in rails (and in other web servers) is implemented as a key/value store which is indexed by a key, typically generated at random for a given session. The server stores that key in a cookie which is gives to the client; the client’s browser gives that cookie back with each request. The server retrieves that key from the cookie and uses it to retrieve the session state. Rails takes care of all of this for you so you don’t typically have to worry about it.
The session store is managed by controllers. Views and models cannot access it without trickery.