Rails 3 default cookie domain for subdomains

In Rails 3 the way you set your default cookie domain to allow your session to be shared across subdomains has changed. In Rails 2.3.5 you would add the following to your application.rb :



config.action_dispatch.session = {:domain =>".mydomain.com"}


In Rails 3 there is now a session_store.rb initialiser, in there you can configure your default domain like so:



Rails.application.config.session_store :cookie_store,
                                  :key => '_app_session',
                                  :domain => '.mydomain.com'


 

Posted by Matthew Ford 

5 comments

May 11, 2010
Aaron said...
this way is cleaner than before, but rails3' doc didn't cover it yet
May 13, 2010
filippo said...
this doesn't work for me...are you sure it's correct? thanks
May 22, 2010
Matthew Ford said...
@filippo are you placing this in the session store initializer, not in your environment files?
May 31, 2010
 said...
I have big trouble :), how can I acces to sett :key?

Rails.application.config.session_store(:key) wont work.

May 31, 2010
Matthew Ford said...
@ernest see http://github.com/rails/rails/blob/4e92134dfa15ae198c714b85376838ffec5a7773/r...

The first argument needs to be the type of session store

Leave a comment...