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

前端之家收集整理的这篇文章主要介绍了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

猜你在找的Ruby相关文章