我在我的导轨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文件中的设置.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。