admitme_sam
admitme_sam

Reputation: 169

Rails server isn't using updated JavaScript

So I've got my web app running fine, I've had to update my JavaScript file for a certain reason. The JavaScript has been updated and pushed up to my server however isn't actually updating on my server.

I've made a link URL change but the URL hasn't updated. I've cleared my cache etc and it hasn't worked.

I'm not 100% sure why its not updating, I have no idea what code you need form me, I've ran multiple compiles, The JavaScript file in question is listed in assets.rb and doesn't update

Anything I can do to get this to update?

Sam

Upvotes: 2

Views: 778

Answers (3)

msuliq
msuliq

Reputation: 250

I am having same issue with Rails 6 and Rails 7 app in development environment. For example, I add console.log into the javascript controller, but it won't log anything as if it is not there. Based on trial and error and found out that running following three commands in the same order usually resolves this problem, usually for some time, and then it re-appears again

rails assets:clobber
rake tmp:cache:clear
rake assets:precompile

Upvotes: 0

Michael Heath
Michael Heath

Reputation: 174

Going out on a limb here. It sounds like you're precompiling your assets and then pushing them to your server. That's fine except whenever you make changes to those files the asset pipeline will change the URL of the new asset. So it keeps referencing the old URL instead of the new ones.

If this is the case, you need to clean or clobber the URLs depending on what version of Rails you're using.

Rails 3:

rake assets:cleanup

Rails 4:

rake assets:clobber

You can read more about it here:

Confusion about rake assets:clean / cleanup on the asset pipeline in rails

Upvotes: 1

jackerman09
jackerman09

Reputation: 2640

You may need to precompile your assets in order for them to update. Try running rake assets:precompile and then re-deploy to your server.

Upvotes: -1

Related Questions