Rails 3 中的子域 cookie 共享不起作用(在 Heroku 上)?

发布于 2024-11-01 00:31:39 字数 488 浏览 0 评论 0原文

我正在尝试让我的网站 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你在我安 2024-11-08 00:31:39

简短的回答:使用 'cookies[:new_cookie] =' 似乎没有从 session_store 配置设置中获取域。

我将 :domain 添加到新的 cookie 中,现在它可以工作了:

cookies.permanent.signed[:new_cookie] = {:value => new_value, :domain => ".dapshare.com"}

对于其他阅读的人,您还需要在删除 cookie 时指定域

cookies.delete :new_cookie, :domain => ".dapshare.com"

(感谢您帮助诊断 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:

cookies.permanent.signed[:new_cookie] = {:value => new_value, :domain => ".dapshare.com"}

For anyone else reading, you also need to specify the domain when deleting the cookie

cookies.delete :new_cookie, :domain => ".dapshare.com"

(Thanks for your help with diagnosis Andrew Marshall.)

箹锭⒈辈孓 2024-11-08 00:31:39

实际上,您可以使用domain => 来指定您的cookie。 :all 而不是域 => Rails 3.1 + 中的“.dapshare.com”:

cookies.permanent.signed[:new_cookie] = {:value => new_value, :domain => :all}

这比直接指定字符串域更灵活。现在,您的应用程序不会在不同的生产域上中断。

You can actually just specify your cookies using domain => :all instead of domain => '.dapshare.com' in Rails 3.1 +:

cookies.permanent.signed[:new_cookie] = {:value => new_value, :domain => :all}

This more flexible than outright specifying a string domain. Now your application won't break on a different production domain.

您的好友蓝忘机已上羡 2024-11-08 00:31:39

我在传递 :all 时遇到了这个问题,似乎无法正常工作。如果您只想用于子域,请尝试以下操作:

Dapshare::Application.config.session_store :cookie_store, :key => '_dapshare_session', :domain => '.dapshare.com'

I encountered this issue, when passing :all doesn't seems to work properly. If you want to use only for subdomains try the following:

Dapshare::Application.config.session_store :cookie_store, :key => '_dapshare_session', :domain => '.dapshare.com'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文