Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cascading/Inherited/Shared Rails configuration environments

Tags:

My staging and production environment Rails configuration are 99% the same with just a few things set differently (e.g. the log level), and I'd really like to eliminate the duplication between the two environment files.

For example, I have something like this:

# config/environments/staging.rb MyApp::Application.configure do   config.cache_classes = true   config.static_cache_control = "public, max-age=31536000"   config.log_level = :debug   # ... end  # config/environments/production.rb MyApp::Application.configure do   config.cache_classes = true   config.static_cache_control = "public, max-age=31536000"   config.log_level = :info   # ... end 

Any recommendations on the best way to create a shared configuration that doesn't also affect my development environment?

like image 1000
coreyward Avatar asked Aug 12 '13 18:08

coreyward


1 Answers

In my projects, I have 3 production-like environments so I have a file called shared_production.rb under config/environments where I put the common configuration

MyApp::Application.configure do   config.cache_classes = true   config.consider_all_requests_local = false   #more shared configs end 

And then in each environment specific config file (production.rb, staging.rb, testing.rb) I do

require File.expand_path('../shared_production', __FILE__) MyApp::Application.configure do   config.log_level = :debug   #more environment specific configs end 
like image 199
akhanubis Avatar answered Sep 20 '22 14:09

akhanubis