加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 19:45:02 所属栏目:百科 来源:网络整理
导读:我的Rails应用程序(在Heroku上运行)有一个分期和生产环境.目前,在staging.rb和production.rb中有很多东西需要在每个文件中单独定义,例如: # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and cac
我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读