rails 4 不在资产文件名中使用摘要,而仅在生产中使用

Sam*_*son 6 ruby ruby-on-rails sprockets ruby-on-rails-4

我有一个 Rails 4 应用程序,它最近进行了大量升级(在 gem 版本和其他一些东西方面)。部署工作正常,但是一旦我们清除了我们的 tmp 目录,我们就会注意到资产在生产中停止工作。发生的事情是出于某种原因在生产模式下,助手没有在任何资产文件名中使用摘要(例如,/javascripts/application.js而不是/javascripts/application-some-digest.js)。这会导致这些资产变为 404,因为它们确实存在于public目录中,并带有其正确的摘要名称,并且 Google App Engine 被设置为独立为公共目录提供静态文件(这一直工作正常)。然而,真正奇怪的是,在暂存模式下,应用程序一切正常,因此我们的生产环境中有一些东西使助手不使用摘要。

然而,更奇怪的是,如果我去RAILS_ENV=production rails consolehelper.asset_path 'application.js'我会得到正确的文件名和摘要。这到底是怎么回事?

是的,我们RAILS_ENV=production rake:assets:precompile在部署之前正在做。

以下是来自的相关部分config/environments/production.rb

  config.eager_load = true
  config.assets.cache_store = :dalli_store
  # Don't force SSL because we need non-ssl cookies.
  config.force_ssl = false
  config.stripe_livemode = true
  config.assets.digest = true
  config.assets.compile = false
Run Code Online (Sandbox Code Playgroud)

以下是来自的相关部分config/environments/shared.rb

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_files = 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

  # Precompile additional assets (application.js, application.css, and all
  # non-JS/CSS are already added)
  config.assets.precompile += ['zxcvbn.js', 'hammer.min.js', 'jquery.ba-throttle-debounce.min.js', 'mediaCheck.js', 'application-no-mq.css', 'lte-ie7.js', 'mailcheck.js', 'browserconfig.xml', 'main.css', 'oamm.js', 'oamm.min.js']

Run Code Online (Sandbox Code Playgroud)

以下是来自的相关部分config/application.rb

    config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )

    # Enable the asset pipeline
    config.assets.enabled = true

    config.log_level = :info

    config.assets.precompile += ['rails_admin/rails_admin.css', 'rails_admin/rails_admin.js']

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
Run Code Online (Sandbox Code Playgroud)

最后,这里是相关的部分config/environments/staging.rb,在某种程度上可以正常工作:

  # Speed up asset compilation on Heroku.
  config.assets.cache_store = :dalli_store
  config.eager_load = true

  config.stripe_livemode = false
Run Code Online (Sandbox Code Playgroud)