我的暂存和生产环境Rails配置99%相同,只是有一些设置不同(例如日志级别),我真的很想消除两个环境文件之间的重复。
例如,我有这样的东西:
# 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
关于创建一个不会影响我的开发环境的共享配置的最佳方式,有什么建议吗?
在我的项目中,我有3个类似生产的环境,所以我在config/environments
下有一个名为shared_production.rb的文件,我在其中放置了通用配置
MyApp::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
#more shared configs
end
然后在每个特定于环境的配置文件(production.rb、staging.rb、testing.rb)中,我执行
require File.expand_path('../shared_production', __FILE__)
MyApp::Application.configure do
config.log_level = :debug
#more environment specific configs
end