Rails assets don't get updated
Asked Answered
G

6

10

I have a Rails 3.1 app and for some reason when I change CSS, the changes don't show up. I did bundle exec rake assets:precompile and it helped once, but now I am stuck with the old CSS no matter what.

Gandhi answered 9/3, 2012 at 21:35 Comment(0)
B
17

As your assets are now precompiled you need to clean them with the following

bundle exec RAILS_ENV=development rake rails_group=assets assets:clean
Buie answered 9/3, 2012 at 21:38 Comment(6)
hmm did not help..? /Users/username/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /Users/username/.rvm/gems/ruby-1.9.3-p0/bin/rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets btw the problem i mentioned shows up in development..Gandhi
Any chance you can tell how to turn off asset precompile for development so that it is possible to see changes made in .css immediately?Gandhi
Delete all the files in public/assets and stop running the precompile task! If the CSS does not show then I bet this is an upgraded app?? In that case check that all you config options match those in the Rails Pipeline Guide upgrading section.Briannebriano
this didnt work as a bundle exec command, rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets worked for me thoughSwayne
I had the same problem and needed to remove config.assets.digest = true from my dev config file to get the asset cache to invalidate when assets were changed.Arp
If you're on Chrome, try using a different tab. Myself and others found that sometimes Chrome was using caching on it's own.Craving
E
6

For my production environment I had to combine a few of the above steps to get my assets recompiled.

First I had to do:

rake assets:clean

Making sure I was in the right environment

Then I needed to delete the public/assets directory that the precompile creates (or just the file that you need to fix, application-<hash>.css for example)

Then finally re-run

rake assets:precompile

And restart my apache server (I use passenger with apache, not tested with nginx)

Excellency answered 4/1, 2016 at 18:48 Comment(0)
E
5

You might want to try rake assets:clean and then rake assets:precompile

Eyeshot answered 9/3, 2012 at 21:39 Comment(2)
did it.. nothing changed (old css is being served).Gandhi
When I did this, I noted in the error that it was performing the rake task in rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets..once I switched it to development it worked nicely! :) thx.Swayne
T
3

For me is was just deleting compiled css/js files from public directory.

It turned out that other dev put it there and didn't let know anyone.

Team answered 2/3, 2014 at 4:22 Comment(1)
I had to do this too, but it's not another dev, it's the precompiler.Excellency
A
3

What worked for me in rails, chrome, mac :

1 - In terminal :

rake assets:clean

2 - In Sublime text or in Finder :

Delete the "Public > Assets" folder

3 - In terminal launch localhost server :

rails s

4 - In chrome :

http://localhost:3000/

5 - Reload chrome clearing cache if relevant :

cmd + shift + R

You should now be able to update your css files and see immediate changes on your localhost just reloading the page

DO NOT RUN "rake assets:precompile" in terminal because it will recreate the folder "assets" in the "public" folder and you won't be able to see updates of your css files directly in your localhost

Adahadaha answered 11/9, 2017 at 15:11 Comment(1)
That last note was my solution. I run rake assets:precompile on development just to test if everything was going to work properly on production. Then I spent 3 hours looking for this solution. Thanks!Crystalloid
W
2

In case any future Googlers find this thread: I had the same problem in the test environment of a Rails 4.2.8 application. None of the above solutions worked. Setting config.serve_static_files = false in config/environments/test.rb solved it.

Bear in mind that this is a temporary fix as it causes all files in the public folder to no longer be served (including 404.html, favicon.ico, robots.txt, etc).

Wellgroomed answered 18/7, 2017 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.