Brian Corrales
corralesonline.com

RAILS 2.0 Sessions

February 13th, 2008 . by brian.corrales

So 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.

[?]
Share This

2 Responses to “RAILS 2.0 Sessions”

  1. comment number 1 by: Jimmy

    You can still use the old file system based session store or the database session store if you configure it correctly in the config. However, cookie sessions will help cut down maintenance issues of having to clear out old sessions.

  2. comment number 2 by: brian.corrales

    Yeah, you can still use whatever system you want, but I found it interesting that the rails team decided to make cookies the default. It’s definitely an improvement.

Leave a Reply

Name

Mail (never published)

Website