www.flickr.com
Michael Kovacs' photos More of Michael Kovacs' photos
Recommend Me Cable Car Software logo

Tuesday, February 21, 2006

Rails realities part 9 (Broken sessions)

For those of you out there that eventually get into a real world application on a domain this tip is for you. When you deploy your rails app and start having sessions created you probably won't notice right away that

http://www.yourdomain.com and http://yourdomain.com

are two different sites to rails and if you visit each of them you will get a different cookie and thus a different session for each of those two URLs.

This is easily rectified by setting the session domain in one of your environment configuration files, probably production.rb.

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.yourdomain.com')

This entry will ensure that visitors to your site will have one session for both the www and non-www variant of your site. But be careful, when you try and run in production on any other machine you need to either comment this change out or make the appropriate change to the setting, otherwise your site will inexplicably stop working and you'll wonder "WTF is going on here?" like I did :-)

Comments:
You have a very fine blog. Great writing style. Keep up the good work. Nice for share this posts. This is Really nice tutorial. That's one thing I'm really looking forward. Looking forward to reading more from you.
Once again, thx. Till next time.

------------------------------------------
Are you play Poker ? Get free $50 bankroll for start poker adventure.
Webmaster - Link exchange with me.
Regards
 

Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?