Rails 3.2.8 - Share Devise Sessions Across Subdoma

2019-02-17 18:32发布

I am trying to set up a simple subdomain-based blog in rails 3.2.8. Basically it will have sites, users (authenticated through Devise), and memberships to connect users to sites. I set up POW so that myapp.dev is working properly. Each site has a subdomain and I can navigate to the site#show action using the subdomains with no problems. My issue is that I can't get the Devise sessions to be shared across subdomains. Everything is working fine on my heroku app, but I would like to be able to test this locally.

When I add the following to session_store.rb, teh sessions seem to work across subdomains, but then I can't log out.

Appname::Application.config.session_store :cookie_store, :key => '_appname_session', domain: :all

When I change the end to domain: ".appname.dev" it doesn't work.

Any help would be greatly appreciated!

1条回答
做个烂人
2楼-- · 2019-02-17 18:50

Make sure you clear your cookies and restart the app.

Appname::Application.config.session_store :cookie_store, :key => '_appname_session', domain: ".appname.dev"

domain: ".appname.dev" is the correct format for the domain option. The beginning period is important.

查看更多
登录 后发表回答