简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM