Rails 2.3 session

Sam*_*ong 6 session activerecord ruby-on-rails

我正在开发rails 2.3.2 app.我需要为订单记录保留session_id,检索它,最后在订单完成时删除session_id.当我使用cookie作为会话存储但它不适用于active_record存储时,它工作.(我重新启动了浏览器,因此没有缓存问题.)

我知道rails 2.3实现了延迟会话加载.我读了一些关于它的信息,但我仍然感到困惑.

有人可以澄清我如何在这种情况下使用session_id吗?

我在做什么......

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.

您将如何在惰性会话(和active_record存储)环境中实现这种情况?

谢谢.

山姆

Gre*_*ict 10

我遇到了编程购物车的同样问题.实际上有两个问题.从rails 2.3开始,会话延迟加载,会话[:session_id]不再有效.您必须先访问会话才能使用它.

puts request.session_options[:id]
session[:session_id] # this forces load of the session in Rails 2.3.x
puts request.session_options[:id]
Run Code Online (Sandbox Code Playgroud)

这输出:

nil
78eb1e371f3378ed98874f9ce372d652
Run Code Online (Sandbox Code Playgroud)

更新:session.session_id已被弃用,因此请改用request.session_options [:id].

更新2:这将在3.x(而非2.3.5)中修复https://rails.lighthouseapp.com/projects/8994/tickets/2268-rails-23-session_optionsid-problem

格雷格