Skip to content

How To: Use subdomains

Roman Pramberger edited this page Dec 1, 2016 · 7 revisions

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:

Rails.application.config.session_store :cookie_store, key: '_my_app_session', domain: '.example.com'

or if you want it works with any domain:

Rails.application.config.session_store :cookie_store, key: '_my_app_session', domain: :all, tld_length: 2

To configure per environment you could use the following:

Rails.application.config.session_store :cookie_store, key: '_my_app_session', domain: {
  production: '.example.com',
  development: '.example.dev'
}.fetch(Rails.env.to_sym, :all)
Clone this wiki locally