rails 4 not using digests in asset filenames, but only in production

和自甴很熟 提交于 2021-02-07 08:01:41

问题


I have a Rails 4 app that was recently heavily upgraded (in terms of gem versions and some other things). Deploys have been working fine, but once we cleared out our tmp directories we noticed that assets stopped working in production. What's happening is for some reason in production mode, the helpers aren't using digests in any of the asset filenames (e.g. /javascripts/application.js instead of /javascripts/application-some-digest.js). This causes those assets to 404, since they do exist with their proper digest names in the public directory and Google App Engine is set up to independently serve static files for the public directory (which has always worked fine). What is really strange, though, is that in staging mode, the app is doing everything properly, so there is something about our production environment that is making the helpers not use digests.

Even weirder, though, is if I go RAILS_ENV=production rails console and do helper.asset_path 'application.js' I get the proper filename with the digest. What on earth could be going on?

And yes, we are doing RAILS_ENV=production rake:assets:precompile before deploying.

Here are the relevant parts from 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

Here are the relevant parts from 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']

Here are the relevant parts from 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'

And finally, here are the relevant parts from config/environments/staging.rb which is somehow working fine:

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

  config.stripe_livemode = false

来源:https://stackoverflow.com/questions/60212729/rails-4-not-using-digests-in-asset-filenames-but-only-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!