views:

238

answers:

2

I want to set default cookie domain for my application to ".mydomain.com" to allow cookie session be preserved across subdomains. There are many places showing how to do it in Rails 2.x but these solutions doesn't work for Rails3. Anyone know how can I set it?

A: 

I've been looking at this:

Rails.application.config.session_store = { :domain => '.domain.com' }

Not sure where it goes...application.rb or environment/production.rb?

Still testing this one. Ryan Bates has a great screen cast showing an easy way to get subdomains working on rails 3 using the constraints method and passing in your class, but didn't mention anything about sessions.

Steve
+3  A: 

I've found the solution. Here it is:

Rails.configuration.session_store :cookie_store, {
  :key    => '_your_app_session',
  :domain => ".domain.com"
}

This should go into config/initializers/session_store.rb. Works great for me.

sickill