[Rails] Sessid.

Fernando Lujan
2006-05-08T17:09:52Z

Jeremy Kemper wrote:
> On May 5, 2006, at 1:19 PM, Fernando Lujan wrote:
>> How can I get the sessid from the current session object?
>
> session.session_id (regardless of the session store.)
>
>
>> For instance, I log in the system, and want to know which sessid
I''m
>> using.
>>
>> I''m storing the session using active_record. Later on, I want
to
>> restore a session finding it using the sessid.
>
> Hmm: this is already done automatically based on cookie or query
> parameter. Do you need to find an arbitrary session?
>
>
> Also, those using the Active Record session store may set the
> underlying session model:
>   CGI::Session::ActiveRecordStore.session_class = MySessionClass
>
> and access the session''s model instance:
>   session.model
>   session.model.is_a?(MySessionClass)
>
> (take a look at the default CGI::Session::ActiveRecordStore::Session
> in actionpack/lib/action_controller/session/active_record_store.rb)
>
>
> So you may
>   # Subclass the default with some additional behavior.
>   class MyApp::Session < CGI::Session::ActiveRecordStore::Session
>     belongs_to :user
>     # ...
>   end
>
>   CGI::Session::ActiveRecordStore.session_class = MyApp::Session

Where can I change this code?

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?