How To: Use subdomains

Sergei Silnov edited this page Sep 26, 2015 · 6 revisions
Clone this wiki locally

If you are using subdomains and Devise you may encounter this problem in internet explorer:

Started GET "/" for 127.0.0.1 at 2012-05-30 19:18:51 +1000
Processing by Users::DashboardController#home as HTML
Completed 401 Unauthorized in 1ms

You need to configure config/initializers/session_store.rb to share across subdomains, for example:

MyApp::Application.config.session_store :cookie_store, key: '_my_app_session', domain: '.example.com'

or if you want it works with any domain:

MyApp::Application.config.session_store :cookie_store, key: '_my_app_session', domain: :all, tld_length: 2

To configure per environment you could use the following:

MyApp::Application.config.session_store :cookie_store, key: '_my_app_session', domain: {
  production: '.example.com',
  development: '.example.dev'
}.fetch(Rails.env.to_sym, :all)