rollni
rollni

Reputation: 21

Rails 3 session resets when redirecting to custom domain page but session stays for heroku default domain

I am using Rails 3's session variable to store some data. Eg. session[:token] = user_token

This session variable exists throughout a single session if I access my app via the heroku domain. (example.heroku.com) However, if I access via the custom domain, (www.example.com) the session variable clears everytime I redirect to another page within the domain.

I could not figure out what is the problem I have tried implementing it with both :cookie_store and :active_record_store, but the same problem persists. I even tried setting the :domain for :cookie_store

MyApp::Application.config.session_store :cookie_store, :key => '_my_app_session', :domain => :all

No luck yet. Please let me know if I missed setting up anything.

Upvotes: 2

Views: 627

Answers (1)

Hardik Joshi
Hardik Joshi

Reputation: 849

You will need to set a default domain in this case. ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:session_domain] = '.example.com'

For more in details please read this blog Cookie-Handling

Upvotes: 1

Related Questions