Skip to main content

Ruby on Rails: How to load session objects into console

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('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] =
That's it!


Anonymous said…
What if you store the session in the DB?
Anonymous said…
AR Session Store:

Find the session id from the cookie and then Session.find_by_id(:my_session_id)
LemmingJoel said…

Popular posts from this blog

Car or Auto Make-Model-Year Database : For Breakfast

Make Model What?If you like me were tasked with loading a database of recent car makes/models/years, you would start by looking on the web and seeing if someone else just has it out there, readily available, hopefully for free, but perhaps for a tiny nominal fee.?If only it was that simple... I looked and looked, and couldn't find anything that would fit the above requirements. So I thought, who would know about US car models better than Kelly Blue Book? So I went on their site, and sure enough they have a javascript file that lists all known to them makes and models of used cars. Since the file is public, I figured it's not really "evil" if I scrape and parse it for my own benefit. Disagree? Have a better source? Then leave a comment.Anyway, to cut the long story short, I'm hoping to save a day or so to someone else who may, like me, be looking for this information. The ruby module shown below retrieves and parses the javascript from KBB site into a Ruby da…

On Ruby on Rails with PostgreSQL, and Acts as Paranoid

Back a few years ago I was researching differences between PostgreSQL and MySQL databases, and chose PostgreSQL because at the time it supported foreign key constraints and many other fantastic SQL extensions that make developer's life a lot easier. Today I am sure MySQL is just as functional as PostgreSQL, and it does appear to be a more popular choice as the Rails DB than MySQL. I still prefer PostgreSQL, it just feels more natural to me coming out of Oracle background, so I am probably biased (who isn't?) Anyway, in the last year and a half or so, I've been writing Rails apps that use PG-based databases and found a few random tricks I'd love to share here. Opinions differ here, but just like accountants like the ancient double entry accounting system, I personally prefer a double validation system - where Rails validates my objects before/after updates, but the database double checks this using proper constraints. Rail's validation system is very robust and ext…

Nagios checks for Sidekiq Queue size monitoring and Joyent RAM size

At Wanelo we are committed to sharing as much of our code as possible with the world, since we are ourselves highly reliant on open source movement (ruby, rails, etc).

Here is a small but growing project with simple BASH shell scripts used by Nagios monitoring system to ensure things are running smoothly.

Please see the examples in the README on how to use it with nagios.