RAILS 2.0 Sessions
February 13th, 2008 . by brian.corralesSo I just updated a project to RAILS 2.0. There’s been a few stumbles on the way, but the main issue I came across was Sessions. It seems that the RAILS team has decided to move away from file-system sessions to cookie sessions. Cookies seem to be much faster than the old file system. The only draw back is that it forces you to utilize session variables as intended…sparingly. Cookies are generally limited to only 4K. There really isn’t any need for you to ever store more than this in your session anyway. It’s just not considered best-practices.
So if you are upgrading to Rails 2.0 and you get some errors, such as a 500 Error, be sure to check how you are handling sessions. Regardless, you’ll need to add the following code into your environments.rb file (don’t forget to restart your server):
config.action_controller.session = {
:session_key => ‘_my_app_session‘,
:secret => ‘hashed_key_of_at_least_30_characters‘
}
If you want to read the documentation, here’s the link: http://caboo.se/doc/classes/CGI/Session/CookieStore.html .
For a really good discussion on Sessions and RAILS, go here.