Lance Pollard
Lance Pollard

Reputation: 79248

Subdomain Session Not Working in Rails 2.3 and Rails 3 on Heroku with/without a Custom Domain?

So I have two heroku apps:

On production-app.com, I have several subdomains using the Heroku custom domains addon with Zerigo (not the wildcard domain addon):

On development-app.heroku.com, I also have those custom subdomains, but since I don't have a custom domain, I just use the wildcard addon.

In my routes.rb, using Subdomain-Fu, I have the subdomains working locally and on both Heroku apps.

The issue I'm facing now is, how do I keep the session in sync between all the subdomains?

I have tried adding this to production.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.production-app.com')

And even combinations of this:

begin
  config.action_controller.session[:domain] = '.production-app.com'
  config.action_controller.session[:session_domain] = '.production-app.com'
rescue
  config.action_controller.session = {:domain => '.production-app.com', :session_domain => ".production-app.com"}
end

...and for the dev site, both of these:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.heroku.com')
# or
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.development-app.heroku.com')

None of those keep the session between subdomains. How do I get this working when I have a custom domain and when I'm just running off a Heroku subdomain?

Thanks!

Upvotes: 4

Views: 2359

Answers (2)

jdscosta91
jdscosta91

Reputation: 704

On development-app.heroku.com, I also have those custom subdomains, but since I don't have a custom domain, I just use the wildcard addon.

Is this addon still available for using custom subdomains like api.mydevdomain.herokuapp.com ?

Upvotes: 0

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

In your config/initializers/session_store.rb, tell rails to set the cookie across all domains:

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

Same as this SO question

If you are wanting to persist your session between "development-app.heroku.com" and "production-app.com" that cannot be done unless those are the same codebase. If they are the same codebase, then use a before_filter on your application controller to redirect to production-app.com

Upvotes: 7

Related Questions