Tatva-Artha

meaning of "it"

Getting session_id in rails

with one comment

If you are using database sessions, rails sessions table stores session information in “sessions” table that contains two columns: “session_id” and “data”.
Now, if you need to know the session_id of current session your first instinct would be to do the following:

session.session_id

This will not work since session is just hash containing name/value pairs and not an ActiveRecord object. So what do we do introspect session’s own information.

Solution: We use “request.session_options”. It is a hash that contains session_id and a few more options related to session.

request.session_options.inspect ={:secure=>false, :secret=>"ZBYULTOIJYLYWVNONXNSWUJCKMVVFPIZCEEGDAIE", :expire_after=>nil, :key=>"_SOMEGT_session", :id=>"4d4999d4650f4b21121c8f2b65917fac", :cookie_only=>true, :httponly=>true, :path=>"/", :domain=>nil}

Here :id is the session_id and :key is the cookie name under which it stores the session_id.

Now I know.

http://www.tatvartha.com/wp-content/plugins/sociofluid/images/digg_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/reddit_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/stumbleupon_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/delicious_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/google_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/twitter_16.png

Related posts:

  1. Ruby Interview Questions I’ve been attending a few Ruby interviews recently. Here are...
  2. Ruby Authlogic: lazy initialization based on defined?() call What is the difference between following two versions of code?...
  3. Working with Authlogic in script/console When probing / debugging issues with Authlogic on rails console,...

Related posts brought to you by Yet Another Related Posts Plugin.

Written by Sharad

September 25th, 2009 at 4:57 am

Posted in All

One Response to 'Getting session_id in rails'

Subscribe to comments with RSS or TrackBack to 'Getting session_id in rails'.

  1. Thank you so much for posting this! It is exactly the problem I have been scratching my head about.

    Craig Lennox

    15 Oct 09 at 6:50 pm

Leave a Reply