ruby-on-rails – 配置session_store.rb来处理分段和生产?
发布时间:2020-12-16 19:24:17 所属栏目:百科 来源:网络整理
导读:我在我的导轨3.1rc6应用程序上有一个分段和生产环境,它使用子域.我为这些环境购买并配置了不同的域名,因为默认的something-something.herokuapp.com不能很好地与子域播放. 当我将session_store.rb设置为一个环境时,一切正常: AppName::Application.config.s
我在我的导轨3.1rc6应用程序上有一个分段和生产环境,它使用子域.我为这些环境购买并配置了不同的域名,因为默认的something-something.herokuapp.com不能很好地与子域播放.
当我将session_store.rb设置为一个环境时,一切正常: AppName::Application.config.session_store :cookie_store,:key => '_sample_app_session',:domain => '.mystagingdomain.co.uk' 但是我似乎不能添加一个条件来允许环境特定的域名. 我试过了 AppName::Application.config.session_store :cookie_store,:domain => '.mystagingdomain.co.uk' if Rails.env.staging? AppName::Application.config.session_store :cookie_store,:domain => '.myproductiondomain.com' if Rails.env.production? 这不行. 解决方法
您可以使用:domain => :全部选项你也可以提供一个:tld_length,如果不同于1.
AppName::Application.config.session_store :cookie_store,:domain => :all 以下是相关的Rails代码 def handle_options(options) #:nodoc: options[:path] ||= "/" if options[:domain] == :all # if there is a provided tld length then we use it otherwise default domain regexp domain_regexp = options[:tld_length] ? /([^.]+.?){#{options[:tld_length]}}$/ : DOMAIN_REGEXP # if host is not ip and matches domain regexp # (ip confirms to domain regexp so we explicitly check for ip) options[:domain] = if (@host !~ /^[d.]+$/) && (@host =~ domain_regexp) ".#{$&}" end elsif options[:domain].is_a? Array # if host matches one of the supplied domains without a dot in front of it options[:domain] = options[:domain].find {|domain| @host.include? domain[/^.?(.*)$/,1] } end end 否则,您还应该能够根据每个环境覆盖config / environments / ENVIRONMENT.rb文件中的设置. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |