应该为环境production.rb(config.public_file_server.enabled,config.assets.compile,config.assets.debug)设置什么值?

时间:2019-02-24 10:04:42

标签: ruby-on-rails ruby-on-rails-5 asset-pipeline

在Rails 5.2.2中,我在生产环境中有一个应用程序,该应用程序在RAILS_ENV=production rails assets:precompile之后进行了预编译。我看到我的应用使用了预编译的资产,因为示例资产的源代码是(我的假设是否正确?):

<img src="/assets/sets/XYZ/LGD-4cd5838b8528caf5a0c1e1e15378df05a088ae79d4ab33e522d871ee783902d4.png" width="63" height="70">

我的production.rb如下:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = true

  # Do not eager load code on boot.
  config.eager_load = true

  # Show full error reports.
  config.consider_all_requests_local = false
  config.action_controller.perform_caching = true

  # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
  # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
  # config.require_master_key = true

  # ############################################################################################
  # Case 1: Commented in order to see static files (pictures) when e.g. Error 404/500. Is it OK?
  # ############################################################################################
  # config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  # ##########################################################################
  # Case 2: Commented. What is a default value in production (when commented)?
  # ##########################################################################
  # config.assets.compile = false

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Store uploaded files on the local file system (see config/storage.yml for options)
  config.active_storage.service = :local

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :warn

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "example_#{Rails.env}"

  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  # Commented:
  # config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  # ###############################################################################
  # Case 3: It's set 'true', because all functions in page work then. Is it OK? 
  # When it's set 'false', two types of things don't work:
  # - 1: javascript countdown:
            # <span id="next_date_countdown"></span>
            # <script type="text/javascript">
            #   // Next date countdown
            #   $('#next_date_countdown').countdown("<%= next_date.deadline.utc %>", function(event) {
            #   var $this = $(this).html(event.strftime(''
            #     + '<span class="bigger">%D</span><span class="smaller">' 
            #     + " <%= t('date.days') %>" + '</span> '
            #     + '<span class="bigger">%H</span><span class="smaller">'
            #     + " <%= t('date.hours_abb') %>" + '</span> '
            #     + '<span class="bigger">%M</span><span class="smaller">'
            #     + " <%= t('date.minutes_abb') %>" + '</span> '
            #     + '<span class="bigger">%S</span><span class="smaller">'
            #     + " <%= t('date.seconds_abb') %>" + '</span> '
            #     ));
            #   });
            # </script>
  # - 2 gem's filterrific "select's" from form_for (otherfilterrific functions work):
  #  <%= form_for_filterrific @filterrific do |f| %>
  #   <div>
  #       <%= f.select(:with_company, 
  #         @filterrific.select_options[:with_company],
  #           { include_blank: t('all_groups') }, class: 'form-control') %>
  #   </div>
  #   <%# add an automated spinner to your form when the list is refreshed %>
  #   <%= render_filterrific_spinner %>
  # <% end %>
  # ##################################################################################
  config.assets.debug = true

  # Suppress logger output for asset requests.
  config.assets.quiet = true

end

我的3个问题均在代码中:

  # ############################################################################################
  # Case 1: Commented in order to see static files (pictures) when e.g. Error 404/500. Is it OK?
  # ############################################################################################
  # config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  # ##########################################################################
  # Case 2: Commented. What is a default value in production (when commented)?
  # ##########################################################################
  # config.assets.compile = false

  # ###############################################################################
  # Case 3: It's set 'true', because all functions in page work then. Is it OK? 
  # When it's set 'false', two types of things don't work:
  config.assets.debug = true

对于这3种情况,我的问题是:生产环境是否设置正确?

0 个答案:

没有答案