Rails 会话不保存 [英] Rails sessions not saving

查看:61
本文介绍了Rails 会话不保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Rails 应用程序从 Rails 2 直接升级到 Rails 4.我正在使用带有 CookieStore 的新 /config/initializers/session_store.rb 文件,但是对于我的会话没有保存的某些原因.

I'm in the process of upgrading a Rails app from Rails 2 directly to Rails 4. I'm using the new /config/initializers/session_store.rb file, with CookieStore, but for some reason my sessions are not saving.

当试图做一些事情时render :text =>"#{request.session_options[:id]}"每次刷新我都会得到一个新的会话 ID.

When trying to do something along the lines of render :text => "#{request.session_options[:id]}" I get a new session ID every refresh.

我在不同的浏览器上尝试过,都应该接受 cookie.

I've tried on different browsers, and all should be accepting cookies.

我不知道发生了什么.为什么这些会话不会持续?!

I have no idea what's going on. Why won't these sessions persist?!

感谢大家的建议.下面是更多信息,以及我注意到的一些事情:

thank you all for your suggestions. Here's a little more information, and a few things I've noticed:

  • 首先,关于我的设置——我在我的 Windows 7 机器上的 Ubuntu VM 上通过 RVM 运行带有 Rails 4/Ruby 2 的服务器.
  • 虽然我是从 Rails 2 升级的,但这仅适用于模型/控制器/视图/等——我为所有支持基础设施生成了一个新的 Rails 4 应用程序.
  • 我在同一个 VM 上创建了另一个应用程序,该应用程序只设置一个会话然后显示,并且工作正常.
  • 会话存储的内容因用户正在执行的操作而略有不同,但通常它只包含一个用户 ID(只是一个整数),偶尔还有更多 --(我第一次注意到这一点是在尝试通过来自 OAuth gem 的 OAuth 令牌.)
  • 我注意到,如果 VM 的系统时钟落后于 Windows 7 主机时钟,则用户 ID 会话将保持不变.这会导致其他问题,尤其是 OAuth,但似乎只是某个地方存在时间问题.我试过从我的环境/development.rb 中删除时区,但这没有帮助.

推荐答案

一般来说,有几个可能的问题是

As a general answer a couple of possible problems are

  • Session 大小超过 4K 限制(显然是这种情况).

    • Session size over 4K limit (which is apparently the case).

      如果您尝试存储超过 4K 的数据,则会引发 CookieOverflow.

    • CookieOverflow is raised if you attempt to store more than 4K of data.

      • CSRF 保护的问题.

        如果安全令牌与预期不符,会话将被重置

      • If the security token doesn't match what was expected, the session will be reset

        这篇关于Rails 会话不保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆