Jon*_*mon 13 ruby ruby-on-rails ruby-on-rails-3
我有一个用于我的Rails应用程序的暂存和生产环境(在Heroku上运行).目前,staging.rb和production.rb中有很多东西,我必须在每个文件中单独定义,例如:
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)
事实并非如此DRY.有没有一种优雅的方法可以有效地将设置从production.rb导入到staging.rb中,然后只是覆盖我希望为登台环境更改的设置?
Pet*_*own 18
我过去所做的是拥有一个包含共享设置的文件,然后在生产和登台环境文件中需要这个.这很有效,因为它允许您在一个位置定义常用设置,然后在单个文件中定义唯一设置:
配置/环境/ shared_production.rb
MyApp::Application.configure do
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
end
Run Code Online (Sandbox Code Playgroud)
配置/环境/ production.rb
require Rails.root.join('config/environments/shared_production')
MyApp::Application.configure do
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :logger
# Url to be used in mailer links
config.action_mailer.default_url_options = { :host => "production.com" }
end
Run Code Online (Sandbox Code Playgroud)
配置/环境/ staging.rb
require Rails.root.join('config/environments/shared_production')
MyApp::Application.configure do
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Url to be used in mailer links
config.action_mailer.default_url_options = { :host => "mysite-dev.com" }
end
Run Code Online (Sandbox Code Playgroud)