Wednesday, May 4, 2011

Ruby on Rails: How to load session objects into console

  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

Session stored in the DB:
# Session.find_by_id(:my_session_id)
# CGI::Session::ActiveRecordStore::Session.find_by_session_id(session_id)

No comments: