会话数据消失 [英] Session data disappearing

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

问题描述

我正在为我的 rails 应用程序编写一个功能,对于任何需要用户登录的任意操作,将使用 ajax 模式提示未登录的用户先注册/登录,然后注册/login,原动作完成.

I'm writing a feature for my rails app whereby for any arbitrary action that requires a user to be logged in, a not-logged-in user will be prompted with an ajax modal to register/login first, and after registration/login, the original action is completed.

我正在尝试在会话中存储有关原始操作的信息.但是,当我尝试在注册/登录结束时访问会话数据时,会话数据正在消失.

I'm trying to store the information about the original action in a session. However, the session data is disappearing when I try to access it at the end of registration/login.

当我检测到匿名"用户时,我会保存有关操作的信息:

When I detect an "anonymous" user, I save info about the action:

session[:interrupted_action] = #info on original action

然后呈现注册/登录模式.

Then render the signup/login modal.

完成后,我再次尝试访问会话信息:

After that is complete, I try to access the session info again:

if session[:interrupted_action]
  #do stuff to complete action

不幸的是,session[:interrupted_action] 现在是 nil.我觉得我在会话中遗漏了一些明显的问题,但我还没有弄清楚.

Unfortunately, session[:interrupted_action] is now nil. I feel like I'm missing some obvious gotcha with sessions, but I haven't been able to figure it out yet.

我应该在这里做什么/调查什么?

What should I be doing/investigating here?

推荐答案

来自 Rails 指南

From Rails guides

config.session_store 通常设置在 config/initializers/session_store.rb 中,并指定用于存储会话的类.可能的值是 :cookie_store 这是默认值、:mem_cache_store 和 :disabled.最后一个告诉 Rails 不要处理会话.也可以指定自定义会话存储.

config.session_store is usually set up in config/initializers/session_store.rb and specifies what class to use to store the session. Possible values are :cookie_store which is the default, :mem_cache_store, and :disabled. The last one tells Rails not to deal with sessions. Custom session stores can also be specified.

因此,如果您使用默认配置,会话将存储在 cookie 中.确保您的浏览器允许存储 Cookie.

So if you are using the default configuration, the session is stored in cookies. Make sure your browser allows cookies to be stored.

您可以检查本地主机的 cookie 中是否有任何条目

You can check if there are any entries in the cookies for your localhost

另外,尝试打印会话本身以查看哈希中是否有任何内容.

Also, try printing the session itself to see if there is anything in the hash.

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

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