在 Rails2 和 Rails3 应用程序之间共享会话
我想通过使用会话 cookie 存储在 Rails 2.3.14 应用程序和 Rails 3.0.10 应用程序之间共享会话。
我发现了一篇很棒的博文,解释了如何设置: http:// blog.kabisa.nl/2010/10/27/share-sessions- Between-rails-2-and-rails-3-applications/
一切正常,直到出现问题有人提出 Rails2 将会话密钥存储为符号,而 Rails3 将会话密钥存储为字符串。另外还提供了一个补丁来解决这个问题:
# lib/patches/cgi/session.rb
require 'cgi/session'
class CGI #:nodoc:
class Session #:nodoc:
def [](key)
@data ||= @dbman.restore
@data[key.to_s]
end
def []=(key, val)
@write_lock ||= true
@data ||= @dbman.restore
@data[key.to_s] = val
end
end
end
该博客是 2010 年的,看起来这个补丁对于 Rails2.3.14 应用程序的工作时间更长。我还了解到 CGI 确实已被弃用,所以我想知道这个补丁是否仍然是解决该问题的正确方法。
有什么建议如何确保 Rails2 和 Rails3 使用相同的数据类型作为会话密钥?
I want to share the session between a Rails 2.3.14 app and a Rails 3.0.10 app by using the session cookie store.
I found an excellent blogpost that explains how to set that up:
http://blog.kabisa.nl/2010/10/27/share-sessions-between-rails-2-and-rails-3-applications/
It all works fine up until the point where the issue is raised that Rails2 stores session keys as symbols, and Rails3 as strings. Also a patch has been supplied to fix this:
# lib/patches/cgi/session.rb
require 'cgi/session'
class CGI #:nodoc:
class Session #:nodoc:
def [](key)
@data ||= @dbman.restore
@data[key.to_s]
end
def []=(key, val)
@write_lock ||= true
@data ||= @dbman.restore
@data[key.to_s] = val
end
end
end
The blog is from 2010, and it looks like this patch is longer working for a Rails2.3.14 app. I also read that CGI really deprecated, so I wonder if this patch is still the right way to resolve the issue.
Any suggestions how to make sure that both Rails2 and Rails3 use the same data type for session keys?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者如果您更喜欢修改 2.3.8,您可以将其添加到 config/initializers/session_store.rb
or if you prefer modify 2.3.8, you can add this to config/initializers/session_store.rb