ruby-on-rails-3sessionrailscasts

Rails 3 - Help! Subdomains - Users Cannot Logout?


I've followed the ascii cast up at http://asciicasts.com/episodes/221-subdomains-in-rails-3

I've set the :domain option to :all in session store:

Rails.application.config.session_store :cookie_store, :key => '_bloggit_session', :domain => :all

Now my users cannot logout.

Any ideas why? I've tried deleting all cookies and then trying again, etc.

I can login, and my session is carried across subdomains, but I can't logout.

I am using rails 3, and authlogic for authentication.

Thanks for any help!


Solution

  • Specify the Domain.

    I had the exact same issue and the culprit was using :domain => :all.

    You'd think that would be all you need but it seems to cause some problems so I had to manually specify the domain with a preceding dot (.), like so:

    :domain => '.lvh.me'

    This fixed the issue in development. You can use different ways to set this in your various environments but I landed on something like this:

    Rails.application.config.session_store :cookie_store, 
      :key => '_bloggit_session',
      :domain => { production:  '.bloggit.com',
                   staging:     '.bloggitstaging.com',
                   development: '.lvh.me' }.fetch(Rails.env.to_sym)