Rails 3 中的子域 cookie 共享不起作用(在 Heroku 上)?
我正在尝试让我的网站 dapshare.com 上的 cookie 同时适用于根地址和“www”子域。
许多其他 stackoverflow 答案(以及有关此主题的精彩 Railscasts vid)建议将此行添加到 session_store.rb:
Dapshare::Application.config.session_store :cookie_store, :key => '_dapshare_session', :domain => :all
这似乎没有什么区别:如果我登录 dapshare.com,我仍然没有登录请访问 www.dapshare.com。
我在这里做错了什么吗?我使用以下代码在 cookie 中存储信息:
cookies.permanent.signed[:thing_to_store] = store_information
感谢您的帮助!
I'm trying to have cookies on my site dapshare.com work for both the root address and the 'www' subdomain.
A lot of other stackoverflow answers (and the great Railscasts vid on this topic) have suggested adding this line to session_store.rb:
Dapshare::Application.config.session_store :cookie_store, :key => '_dapshare_session', :domain => :all
This doesn't seem to make a difference: if I log in at dapshare.com, I still am not logged in at www.dapshare.com.
Am I doing something wrong here? I am using the following code to store information in the cookie:
cookies.permanent.signed[:thing_to_store] = store_information
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答:使用 'cookies[:new_cookie] =' 似乎没有从 session_store 配置设置中获取域。
我将 :domain 添加到新的 cookie 中,现在它可以工作了:
对于其他阅读的人,您还需要在删除 cookie 时指定域
(感谢您帮助诊断 Andrew Marshall。)
Short answer: using the 'cookies[:new_cookie] =' does not seem to grab the domain from the session_store config settings.
I added the :domain to the new cookie and it now works:
For anyone else reading, you also need to specify the domain when deleting the cookie
(Thanks for your help with diagnosis Andrew Marshall.)
实际上,您可以使用domain => 来指定您的cookie。 :all 而不是域 => Rails 3.1 + 中的“.dapshare.com”:
这比直接指定字符串域更灵活。现在,您的应用程序不会在不同的生产域上中断。
You can actually just specify your cookies using domain => :all instead of domain => '.dapshare.com' in Rails 3.1 +:
This more flexible than outright specifying a string domain. Now your application won't break on a different production domain.
我在传递 :all 时遇到了这个问题,似乎无法正常工作。如果您只想用于子域,请尝试以下操作:
I encountered this issue, when passing :all doesn't seems to work properly. If you want to use only for subdomains try the following: