Rails的2.3会话 [英] Rails 2.3 session

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

问题描述

我开发一个Rails 2.3.2应用程序。 我需要保持SESSION_ID一个订单记录,检索和最终删除SESSION_ID当订单完成。 它工作时,我用饼干会话存储,但它并不适用于active_record店。 (我重新启动我的浏览器,所以没有缓存的问题。)

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.)

我知道导轨2.3实现了懒会话负载。 我读了一些关于它的信息,但我仍然感到困惑。

I know rails 2.3 implements lazy session load. I read some info about it but am still confused.

有人能澄清我是如何使用的session_id对于此种情况?

Can somebody clarify how I use session_id for such a case?

我在做什么是...


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存储)环境中这种情况?

How would you implement such a case in lazy session(and active_record store) environment?

感谢。

山姆

推荐答案

我遇到了同样的问题,编写一个购物车。实际上有两个问题。 由于轨道2.3,会话延迟加载和会话[:SESSION_ID]不再起作用。你必须访问会话,然后才能使用它。

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]

此输出:

nil
78eb1e371f3378ed98874f9ce372d652

更新:session.session_id已去precated,所以使用request.session_options [:ID]。而不是

Update: session.session_id has been deprecated, so use request.session_options[:id] instead.

更新2 :这将固定在3.X(不是2.3.5)<一href="https://rails.lighthouseapp.com/projects/8994/tickets/2268-rails-23-session%5Foptionsid-problem">https://rails.lighthouseapp.com/projects/8994/tickets/2268-rails-23-session%5Foptionsid-problem

Update 2: This will be fixed in 3.x (not 2.3.5) https://rails.lighthouseapp.com/projects/8994/tickets/2268-rails-23-session%5Foptionsid-problem

格雷格

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

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