Rails asset paths missing fingerprints in production

We just deployed the Rails 4.0.3 application for production and found that the resource paths generated by stylesheet_link_tag and javascript_link_tag do not have fingerprints. Therefore, instead of a request of type application-c841bd1c82c25bb1de8452d2338479f7.js , the page is just a request for application.js .

RAILS_ENV=production bundle exec rake assets:precompile successfully and generates fingerprints.

The bits from config/environments/production.rb that seem relevant are as follows:

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

This works on our own Apache server, not Heroku. I looked around a bit and found similar problems, but none of the troubleshooting steps for them helps. Thanks.

Additional Information

In case this is useful, here is the full content (deleted lines with comments) of our configuration files:

application.rb

 require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end module Ctrc class Application < Rails::Application config.ceal.application_title = "CTRC Budgeting" config.encoding = "utf-8" config.filter_parameters += [:password] config.active_support.escape_html_entities_in_json = true config.assets.enabled = true config.assets.version = '1.0' config.pmacs_redmine.project_identifier = 'itmat-gcrc' config.app_data_path = '/data/web/apps/itmat/ctrc' config.paperclip_defaults = { path: "/data/web/apps/itmat/ctrc/:attachment/:id/:style/:basename.:extension" } if ENV['RAILS_RELATIVE_URL_ROOT'] config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] + '/assets' end end end 

production.rb

 Ctrc::Application.configure do config.cache_classes = true config.consider_all_requests_local = false config.action_controller.perform_caching = true config.serve_static_assets = false config.assets.compress = true config.assets.compile = false config.assets.digest = true config.i18n.fallbacks = true config.active_support.deprecation = :notify config.eager_load = true end 

I know that the application is working, because if I installed

 config.assets.compile = true 

in this file, CSS and JavaScript are compiled and requested correctly.

I include these assets on the page as follows:

 <%= stylesheet_link_tag "application", media: "all" %> <%= javascript_include_tag "application" %> 

but he still creates references to these assets as follows:

 <link href="/apps/itmat/ctrc/stylesheets/application.css" media="all" rel="stylesheet"> <script src="/apps/itmat/ctrc/javascripts/application.js"></script> 

instead of the fingerprints that I expected to see.

+6
source share
2 answers

I had a similar problem and this turned out to be an AssetSync gem problem . Either setting config.assets.compile = true or removing the gem resolved the problem. Generally, compiling assets on the fly and using your Rails of your assets may be acceptable if you use a CDN, but a different approach is usually recommended.

+1
source

For 4.x rails, be sure to set the following:

configurations / application.rb

 config.assets.enabled = true config.assets.version = '1.0' 

configurations / environment / production.rb

 config.assets.compile = false 
0
source

Source: https://habr.com/ru/post/971936/


All Articles