Ruby-on-rails 在 rails 3 中查找会话 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4824829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding the session id in rails 3
提问by Austin
How can I get the current session id in rails 3?
如何在 rails 3 中获取当前会话 ID?
I've tried the following with no luck:
我试过以下没有运气:
session[:session_id]
session['session_id']
session[:id]
session['id']
session.id
session.session_id
回答by splicer
Have you tried the following?
您是否尝试过以下方法?
request.session_options[:id]
回答by whatbird
It also returns the session ID:
它还返回会话 ID:
session[:session_id]
回答by equivalent8
If you need to see data written in Session store for given session id from Rails console you can:
如果您需要从 Rails 控制台查看为给定会话 ID 写入会话存储中的数据,您可以:
a = Rails.application.config.session_store.new(app, Rails.application.config.session_options)
a.class # => ActionDispatch::Session::RedisStore
a.get_session(ENV, '07319b2485be9ac4850664cd47cede38')
# or a.find_session(ENV, '07319b2485be9ac4850664cd47cede38')
appandENVare set when you start rails console, don't need to set those
app并ENV在您启动 rails 控制台时设置,不需要设置这些
you can get the session_idvia some a browser plugin dealing with cookies or (cookie inspector, cookies manager, ...)
您可以session_id通过一些处理 cookie 的浏览器插件或(cookie 检查器、cookie 管理器,...)
回答by RinoFM
I can't test it right now but as far as I know the session id variable changed from 'id'to 'session_id'on Rails 3, have you tried that one? Hope it works for you.
我现在无法对其进行测试,但据我所知,Rails 3 上的 session id 变量从 更改'id'为'session_id',您尝试过吗?希望对你有效。

