配置session_store.rb以处理分段和生产? [英] Configure session_store.rb to handle staging and production?

查看:117
本文介绍了配置session_store.rb以处理分段和生产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的rails 3.1rc6应用程序使用子域的分期和生产环境。我为这些环境购买和配置了不同的域名,因为默认的something-something.herokuapp.com不能很好地与子域。



当我为一个环境设置session_store.rb时,一切正常:

 code> AppName :: Application.config.session_store:cookie_store,:key => '_sample_app_session',:domain => '.mystagingdomain.co.uk'

但我似乎不能添加一个条件用于特定于环境的域名。



我试过了

  AppName :: Application.config。 session_store:cookie_store,:key => '_sample_app_session',:domain => '.mystagingdomain.co.uk'if Rails.env.staging? 
AppName :: Application.config.session_store:cookie_store,:key => '_sample_app_session',:domain => '.myproductiondomain.com'if Rails.env.production?

这不起作用。

解决方案

您可以使用:domain => :all 选项。如果不同于1,也可以提供:tld_length

  AppName :: Application.config.session_store:cookie_store,:key => '_sample_app_session',:domain => :all 

这里是相关的Rails代码

  def handle_options(options)#:nodoc:
options [:path] || =/

if options [:domain] == :all
#如果有一个提供的tld长度然后我们使用它否则默认域regexp
domain_regexp = options [:tld_length]? /([^.]+\.?){#{options [:tld_length]}}$/:DOMAIN_REGEXP

#如果主机不是ip并且匹配域regexp
# ip确认到域regexp所以我们明确检查ip)
选项[:域] = if(@host!〜/^[ \d.]+$/)&& (@host =〜domain_regexp)
。#{$&}
end
elsif options [:domain] .is_a?数组
#如果主机匹配提供的域之一,在其前面没有一个点
options [:domain] = options [:domain] .find {| domain | @ host.include? domain [/ ^ \。?(。*)$ /,1]}
end
end

否则,您还应该能够在每个环境的基础上覆盖 config / environments / ENVIRONMENT.rb 文件中的设置。 p>

I have a staging and a production environment on my rails 3.1rc6 app which uses subdomains. I've bought and configured different domain names for these environments, because the default something-something.herokuapp.com doesn't play nicely with subdomains.

When I set session_store.rb to this for one environment, everything works fine:

AppName::Application.config.session_store :cookie_store, :key => '_sample_app_session' , :domain => '.mystagingdomain.co.uk' 

But I can't seem to add in a conditional to allow for the environment-specific domain names.

I've tried

AppName::Application.config.session_store :cookie_store, :key => '_sample_app_session' , :domain => '.mystagingdomain.co.uk' if Rails.env.staging?
AppName::Application.config.session_store :cookie_store, :key => '_sample_app_session' , :domain => '.myproductiondomain.com' if Rails.env.production?

which doesn't work.

解决方案

You can use the :domain => :all option. You can also provide a :tld_length, if different than 1.

AppName::Application.config.session_store :cookie_store, :key => '_sample_app_session' , :domain => :all

Here's the relevant Rails code

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

Otherwise, you should also be able to override the settings in the config/environments/ENVIRONMENT.rb file on a per-environment basis.

这篇关于配置session_store.rb以处理分段和生产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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