ruby-on-rails – 删除staging.rb和production.rb之间的重复

我的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

这不是干有没有一个优雅的方式,我可以有效地将设置从production.rb导入到staging.rb,然后只是覆盖我想为分段环境更改的设置?

解决方法

过去我做了一个包含共享设置的文件,然后在生产和分段环境文件中要求这个文件.这一切都很好,因为它允许您在一个地方定义通用设置,然后在各个文件中定义唯一的设置:

配置/环境/ 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

配置/环境/ 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

配置/环境/ 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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...