circa75 Home | About circa75 | Articles | Links | Contact Us

Posted by gustav at 06:01AM, Tuesday, December 02nd, 2008

Rails session_store/file_store bug

If you set the session_store in your environment file to use :file_store, and attempt to stick any non-string values in your session, you'll get an error. Either don't store non-string objects in session, or don't use file store.

I'm using Rails 2.1.2, and had a particular requirement to NOT stick session information in the database. I edited my config file like so:

config.action_controller.session_store = :file_store

and it took me a while to figure out why I was getting errors like:

NoMethodError (private method `gsub' called for :site_version:Symbol):
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cgi.rb:342:in `escape'

Looks like the arg to that escape method generating the error is supposed to be a string. If what's in your session isn't a string, performing string substitution is unlikely to work. Googling around indicates that a lot of people run into this when trying to set cookies.

It's a simple enough solution for my requirements: set the session store to use :memory_store instead of :file_store.

The moral (directed to whoever on the Rails team borked this): if you're using a language without type checking, don't make dumb assumptions about types!
circa75 Home | About circa75 | Articles | Links | Contact Us

All content copyright © 2001-2009 the owners of