RSS

>Ruby on Rails: How to load session objects into console

06 Dec

>

This took a little bit of poking around, so I decided to post it here.

Basically I was tracking down a bug, which resulted in a corrupt object (cart) in the web session. So I thought, it would be nice to play with this object in the console to see what’s up… But how do I get it in there?

There may be a more elegant way to do this but here is how I got it to load:

  1. Look in tmp/sessions and find the most recent file (ls -alrt on UNIX). Let’s say the file is called ‘tmp/sessions/ruby_sess.8eb9614a7e4e1e3b’
  2. Open console and type:
    >> session = Marshal.load(File.open('tmp/sessions/ruby_sess.8eb9614a7e4e1e3b'))
    => {"hash"=>{:cart=...
    >> cart = session["hash"][:cart]
    ....
    

    In this case I was trying to access a cart object in the session, which was placed in the session with:session[:cart] = Cart.new

That’s it!

About these ads
 
3 Comments

Posted by on December 6, 2006 in Ruby on Rails, Technology

 

3 Responses to >Ruby on Rails: How to load session objects into console

  1. Anonymous

    September 9, 2008 at 1:29 pm

    >What if you store the session in the DB?

     
  2. Anonymous

    December 16, 2008 at 7:31 am

    >AR Session Store:Find the session id from the cookie and then Session.find_by_id(:my_session_id)

     
  3. LemmingJoel

    March 6, 2010 at 9:15 pm

    >CGI::Session::ActiveRecordStore::Session.find_by_session_id(session_id)

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: