我可以强制 Rails 会话从字符串重新加载吗?

发布于 2024-07-30 02:28:35 字数 507 浏览 3 评论 0原文

我有一个与 Rails 2.3.3 一起使用的第三方应用程序(上传进度条 - swfupload),无法传递会话信息或 cookie。 不过,我可以将应用程序中的会话数据打包到 URI 中,它将用于上传文件并在获取文件时检索该文件。

问题是,我在网络上看到的所有神奇的 hack 都不能与 2.3.3 一起工作。 我不知道具体原因,但我什至尝试过使用 swfupload 的最小 RESTful 演示应用程序,它的呕吐方式与我的一样。

我所需要的只是一种强制从已知包含会话数据的字符串重新加载会话的方法。 大概是这样的:

if session[:user_id]
  do stuff
else
  session.reload(session_string_from_uri)
end

你明白了。

不,我对尝试另一个 Rails 上传器解决方案不感兴趣。 我已经经历了足够多的失败,所以我将坚持使用这个解决方案,因为对我当前问题的简单回答将解决我的问题。

I have a third-party app (an upload progress bar - swfupload) that I'm using with rails 2.3.3 that cannot pass along session information or cookies. I can, however, pack the session data from my app into the URI it will use to upload a file and retrieve that when I get the file.

The trouble is, none of the magic hacks I see floating around the net work with 2.3.3. I don't know the specific details of why, but I've even tried the minimal RESTful demo application that uses swfupload and it pukes the same way mine does.

All I need is a way to force a reload of the session from a string, known to contain session data. Something along the lines of:

if session[:user_id]
  do stuff
else
  session.reload(session_string_from_uri)
end

You get the idea.

No, I'm not interested in trying yet another uploader solution for Rails. I've had enough of them fail that I'm going to stick with this solution because a simple answer to my current question will solve my problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

英雄似剑 2024-08-06 02:28:35

您需要使用机架中间件从随 Flash 请求一起发布的数据中恢复会话。 这是一篇很好的文章,解释了这一点: http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload- rack-middleware-for-flash-uploads-that-degrade-graceively/comment-page-1/

You need to use a rack middleware to restore the session from data posted along with the Flash request. Here is a very good article explaining this: http://jetpackweb.com/blog/2009/10/21/rails-2-3-4-and-swfupload-rack-middleware-for-flash-uploads-that-degrade-gracefully/comment-page-1/

强辩 2024-08-06 02:28:35

不确定这是否适合您,但我的 swfuploader 修复很简单,因为我们有数据库会话。

_options['session_id'] = params[ _options['session_key'] ]   
session = Session.find_by_session_id(_options['session_id'])      

Not sure if this is an option for you, but my swfuploader fix was easy because we have DB sessions.

_options['session_id'] = params[ _options['session_key'] ]   
session = Session.find_by_session_id(_options['session_id'])      
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文