Rails Asset Pipeline - wrong fingerprint

2019-08-30 07:26发布

问题:

My Rails 4 application has new.html.erb which has a reference to form.html.erb:

# app/assets/templates/jobs/new.html.erb
...
<ng-include src="'<%= asset_path("jobs/form.html") %>'"></ng-include>
...

# app/assets/templates/jobs/form.html.erb
my form is here

(ng-include is AngularJS directive)

The problem is, that when form.html.erb changes, the production environment still loads the old form.html.erb. This is happening probably because new.html.erb hasn't been changed, and therefore has the same old fingerprint, which points to form.html.erb with the old fingerprint.

What is the Rails way to handle this?

回答1:

To answer this, in-case anyone else has the issue, you need to run the following:

rake assets:clean
rake assets:precompile
touch tmp/restart.txt

After running the rake task, you need to restart Rack, otherwise the new precompiled assest files will not be loaded.