Herm Herm - 1 year ago 112
Ruby Question

Rails and devise after sign in/out path and subdomains

I have a production app as well as a staging app. For this question let's assume the following:

  1. Production = foo.com

  2. Staging = staging.foo.com

Each user of my app will have their own subdomain as well. Ex.

  1. Production = user.foo.com

  2. Staging = user.staging.foo.com

After deploying my app to heroku, I sign in from 'staging.foo.com/login' after which devise redirects me to 'user.foo.com'. I would expect it to redirect to 'user.staging.foo.com' since I used the sign in url from that domain. Since I'm redirected to an incorrect domain, the browser presents me with an error stating that the server is not available.

Here is some of my code:


def after_sign_in_path_for(resource)
authenticated_root_url( subdomain: 'user' )


config.action_controller.default_url_options = { host: 'staging.foo.com' }


Rails.application.config.session_store :cookie_store, key: '_foo_session', domain: "staging.foo.com" , tld_length: 3

If I manually type in the 'user.staging.foo.com' url after signing in, I can see the correct root page. Any ideas about what I'm missing?

Answer Source

Change this:

config.action_controller.default_url_options = { host: 'staging.foo.com' }

To this:

config.action_controller.default_url_options = { domain: 'staging.foo.com' }