[Rails] Sessid.

Jeremy Kemper
2006-05-08T17:37:24Z

On May 8, 2006, at 10:09 AM, Fernando Lujan wrote:
> I want something like this...
>
> In my app.
>
> session[:user_id] = "15"
> session[:group_id] = "18"
>
> This will generate a session. I will store it in a database, and
> later on I want to restore it. Without cookies and so forth.
>
> Later, I want something like restoring a session.
>
> @id = ID OF THE PREVIOUS CREATED SESSION.
> @session = Session.find(:first, :conditions=> ["sessid = ?",
@id])
> @session[:user_id] #returns the user id of the session
>
> I know that the session data attribute is marshaled. How can I
> restore it?

You don''t need any of these mechanics - session load/save is
automatic.  Just use session directly and forget about it.

When you do session[:user_id] = foo, the session is created if not
present, updated with :user_id => foo.  When the action is complete,
the session is serialized and stored for you.  On next page load,
session is reconstituted according to the value of cookie OR query
parameter _session_id.

jeremy