4

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!

Lance
  • 75,200
  • 93
  • 289
  • 503

2 Answers2

7

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

Community
  • 1
  • 1
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
0

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 ?

jdscosta91
  • 706
  • 1
  • 8
  • 16