子域会话无法在Heroku中使用Rails 2.3和Rails 3使用/不使用自定义域? [英] Subdomain Session Not Working in Rails 2.3 and Rails 3 on Heroku with/without a Custom Domain?

查看:110
本文介绍了子域会话无法在Heroku中使用Rails 2.3和Rails 3使用/不使用自定义域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有两个heroku应用程序:





production-app.com 上,我有几个使用Heroku自定义域名插件和Zerigo(不是通配符域名插件)的子域名: b
$ b


  • http://blog.production-app.com



  • development-app.heroku.com 上,我也有这些自定义子域名,但由于我没有自定义域名,我只是使用通配符插件



    routes.rb 中,使用 Subdomain-Fu ,我在本地和两个Heroku应用程序中都有子域名。



    我现在面临的问题是,如何保持所有子域之间的会话同步



    我试过添加这个到 production.rb

      ActionController :: CgiRequest :: DEFAULT_SESSION_OPTIONS。 update(:session_domain => '.production-app.com')

    即使是这样的组合:

      begin 
    config.action_controller.session [:domain] ='.production-app.com'
    config.action_controller.session [:session_domain] ='.production-app.com'
    rescue
    config.action_controller.session = {:domain => '.production-app.com',:session_domain => .production-app.com}
    end

    ...以及dev网站,这两个:

      ActionController :: CgiRequest :: DEFAULT_SESSION_OPTIONS.update(:session_domain =>'.heroku.com ')
    #或
    ActionController :: CgiRequest :: DEFAULT_SESSION_OPTIONS.update(:session_domain =>'.development-app.heroku.com')

    这些都不会保留子域之间的会话。当我有一个自定义域名,并且刚刚运行Heroku子域名时,我该如何获得这项工作?



    谢谢!


    <在您的config / initializers / session_store.rb中,告诉rails在所有域中设置cookie:

    <$

p $ p> Rails.application.config.session_store:cookie_store,:key => '_yourapp_session',:domain =>:所有


So I have two heroku apps:

On production-app.com, I have several subdomains using the Heroku custom domains addon with Zerigo (not the wildcard domain addon):

On development-app.heroku.com, I also have those custom subdomains, but since I don't have a custom domain, I just use the wildcard addon.

In my routes.rb, using Subdomain-Fu, I have the subdomains working locally and on both Heroku apps.

The issue I'm facing now is, how do I keep the session in sync between all the subdomains?

I have tried adding this to production.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.production-app.com')

And even combinations of this:

begin
  config.action_controller.session[:domain] = '.production-app.com'
  config.action_controller.session[:session_domain] = '.production-app.com'
rescue
  config.action_controller.session = {:domain => '.production-app.com', :session_domain => ".production-app.com"}
end

...and for the dev site, both of these:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.heroku.com')
# or
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain => '.development-app.heroku.com')

None of those keep the session between subdomains. How do I get this working when I have a custom domain and when I'm just running off a Heroku subdomain?

Thanks!

解决方案

In your config/initializers/session_store.rb, tell rails to set the cookie across all domains:

Rails.application.config.session_store :cookie_store, :key => '_yourapp_session', :domain=>:all

Same as this SO question

If you are wanting to persist your session between "development-app.heroku.com" and "production-app.com" that cannot be done unless those are the same codebase. If they are the same codebase, then use a before_filter on your application controller to redirect to production-app.com

这篇关于子域会话无法在Heroku中使用Rails 2.3和Rails 3使用/不使用自定义域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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