Rails 2.3 会议

编程入门 行业动态 更新时间:2024-10-27 18:30:14
本文介绍了Rails 2.3 会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个 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 78eb1e371f3378ed98874f9ce372d652

Update: 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 会议

本文发布于:2023-10-31 05:40:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会议   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!