Configure session_store.rb to handle staging and production?

后端 未结 2 1892
夕颜
夕颜 2021-02-08 08:07

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 th

2条回答
  •  你的背包
    2021-02-08 08:45

    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.

提交回复
热议问题