Subdomains and Rails

less than 1 minute read

I was trying to setup the proper environment settings in Rails 2 to support cross-subdomain cookie sharing (so the user doesn’t have to login again if they manage multiple subdomain accounts). I was experiencing some inconsistencies when trying to make sure it was working. Here is a tip:

Clear your cookies (the Firefox Web Developer plug-in is great for viewing/deleting cookies being assigned) before testing this! If you have any old cookies from an old login session before you converted to subdomains, you’ll experience some oddities that will make you think it isn’t working.

BTW, if you are using the Ruby on Rails Wiki page for customizing your session or cookie settings, you’ll notice that the wiki provides multiple ways to change the session domain. This is the line that worked for me to customize the domain using Rails 2.0.2:

ActionController::Base.session_options[:session_domain] = '.mydomain.com'

Categories: ,

Updated: