Reputation: 171399
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?
Upvotes: 1
Views: 1643
Reputation: 412
Normally, assets are "precompiled" only in production/deployed environments. That means that by default there shouldn't be a folder at public/assets/
while you develop (Sprockets compiles assets on-the-fly for you in development mode).
If you accidentally have run rails assets:precompile
in development, you'll have an extra folder here (public/assets/
) which does not get checked in to your repository.
But if it does exist, then its existence overrides Sprocket's development mode setting to recompile on every pageload, forcing your browser to load the already compiled (and stale) asset from public/assets/
... If you do have a folder at public/assets/
, be sure to remove it completely with rm -rf public/assets/
(Ironically, running rails assets:precompile
or rake assets:precompile
, while it does force a one-time recompile and seemingly gives you your latest JS compile, doing this in development is typically what causes the problem of Sprockets getting stuck in the first place)
Next, force Sprockets to bust the thumbprint cache using:
rails assets:clean
rails assets:clobber
touch tmp/restart.txt
You must actually touch this empty tmp/restart.txt
file -- not merely restart your Rails dev environment, to force Sprockets to bust the thumbprint cache.
To debug further, set assets.debug = true
in your environment file.
Upvotes: 4