问题描述
我有一个 2.2.3 的应用程序,我升级到了 2.3.2
I have a 2.2.3 app which I upgraded to 2.3.2
这是一个多站点(使用子域),可为所有站点创建一个顶级会话.
It's a multi-site (using subdomain) that creates one top level session for all sites.
这是我在 production.rb 中更改域的方式:
This is how I change the domain in production.rb:
ActionController::Base.session_options[:domain] = "example.com"
# in rails 2.2.2, this is what i used to do:
# ActionController::Base.session_options[:session_domain] = "example.com"
我升级后开始发生奇怪的事情我无法再使用 Restful 身份验证登录;它确实对我进行了身份验证,但是一旦我被重定向,它就会要求我再次登录.
Strange things started to happen after I upgradedI can no longer log in using restful authentication; it does authenticate me, but as soon as I'm redirected, it would ask me to log in again.
正如我所说,我使用restful_authentication,我也使用passenger 2.1.2.有人可以帮忙吗?
As I said, I use restful_authentication and I also use passenger 2.1.2.Can anyone help?
推荐答案
Olly 的回答是正确的,在 rails 2.3 中应该是:
Olly's answer is correct, in rails 2.3 it should be:
config.action_controller.session[:domain] = '.example.com'
我只想补充一点,如果您还没有创建某些会话选项,则在使用它时可能会收到此信息:
I just wanted to add that if you don't already have some session options created you may receive this when using that:
undefined method `[]=' for nil:NilClass
在这种情况下,您应该改用它(它会创建会话变量而不是更新它):
In that case you should use this instead (which creates the session variable instead of updating it):
config.action_controller.session ||= {}
config.action_controller.session[:domain] = '.example.com'
显然 Rails 2.2.2 项目使用了不同的东西.域"应命名为session_domain"并去掉域前面的句点字符.试试这个:
apparently Rails 2.2.2 projects use something different. "domain" should be named "session_domain" and take the period character off the front of the domain. Try this:
config.action_controller.session ||= {}
config.action_controller.session[:session_domain] = 'example.com'
这篇关于使用子域在 rails 2.3.2 应用程序中丢失会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!