我正在开发一个 rails 2.3.2 应用程序.我需要为订单记录保留 session_id,检索它并最终在订单完成时删除 session_id.当我使用 cookie 作为会话存储时它工作,但它不适用于 active_record 存储.(我重新启动了浏览器,所以没有缓存问题.)
我知道 rails 2.3 实现了延迟会话加载.我阅读了一些关于它的信息,但仍然很困惑.
有人可以澄清我如何在这种情况下使用 session_id 吗?
我正在做的是...
用户通过多个页面进行订购.没有注册,也没有登录.所以我将 session_id 保留在订单记录中,以便其他用户无法访问订单.@order = Order.last :conditions => {:id => params[:id], :session_id => session[:session_id] }订单完成后,我将 nil 设置为 session_id 列.您将如何在惰性会话(和 active_record 存储)环境中实现这种情况?
谢谢.
山姆
解决方案我在为购物车编程时遇到了同样的问题.其实有两个问题.从 rails 2.3 开始,会话被延迟加载并且 session[:session_id] 不再有效.您必须先访问会话,然后才能使用它.
放入 request.session_options[:id]session[:session_id] # 这会强制在 Rails 2.3.x 中加载会话把 request.session_options[:id]输出:
nil78eb1e371f3378ed98874f9ce372d652更新:session.session_id 已被弃用,因此请改用 request.session_options[:id].
更新 2:这将在 3.x(而非 2.3.5)中修复rails.lighthouseapp/projects/8994/tickets/2268-rails-23-session_optionsid-problem
格雷格
I am developing a rails 2.3.2 app. I need to keep session_id for an order record, retrieve it and finally delete the session_id when the order is completed. It worked when I used cookies as session store but it doesn't for active_record store. (I restarted my browser, so no cache issue.)
I know rails 2.3 implements lazy session load. I read some info about it but am still confused.
Can somebody clarify how I use session_id for such a case?
What I am doing is...
A user make an order going through several pages. There is no sign-up, neither login. So I keep session_id in the order record so that no other user can access the order. @order = Order.last :conditions => {:id => params[:id], :session_id => session[:session_id] } When the order is finished, I set nil to session_id column.How would you implement such a case in lazy session(and active_record store) environment?
Thanks.
Sam
解决方案I ran into the same problem programming a shopping cart. There are actually two issues. As of rails 2.3, sessions are lazy loaded and session[:session_id] no longer works. You must access the session before you can work with it.
puts request.session_options[:id] session[:session_id] # this forces load of the session in Rails 2.3.x puts request.session_options[:id]This outputs:
nil 78eb1e371f3378ed98874f9ce372d652Update: session.session_id has been deprecated, so use request.session_options[:id] instead.
Update 2: This will be fixed in 3.x (not 2.3.5) rails.lighthouseapp/projects/8994/tickets/2268-rails-23-session_optionsid-problem
Greg
更多推荐
Rails 2.3 会议
发布评论