26

I've been developing a site in rails, everything going relatively smooth. Suddenly my changes to the views and assets no longer show up. I change a stylesheet or some html and reload my browser at http://0.0.0.0:3000 and nothing changes. So I restart WEBrick and still nothing's changed. This is even the case if I change an image entirely.

The only way to get the new changes is to precompile the assets:

C:\Users\me\website>rake assets:precompile
C:/Ruby193/bin/ruby.exe C:/Ruby193/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets

Why is it showing production as the RAILS_ENV? Maybe my development environment somehow turned into the production environment? But even then I shouldn't need to precompile assets to get changes reflected. Anyway Rails.env.development? returns true and Rails.env.production? returns false in controllers and erb files.

I've tried deleting my /tmp directory to no avail.

I had to add the following line to config/application.rb in order to get Heroku to work with compass:

config.assets.initialize_on_precompile = false

However, removing that line didn't help my issue anyway.

at.
  • 50,922
  • 104
  • 292
  • 461

5 Answers5

47

Delete the contents of your public/assets/ directory. That's where precompiled files go, and they're served if they exist, rather than the request falling through to Sprockets. You can safely just nuke the whole directory, and things should work again.

Chris Heald
  • 61,439
  • 10
  • 123
  • 137
12

I just want to add something that can make the accepted answer a little bit easier to do. Here's what I use:

rake tmp:cache:clear
rails server
vpibano
  • 2,415
  • 1
  • 13
  • 26
  • 1
    I renamed an SVG logo and it would not update in my views. `rake tmp:cache:clear` fixed it for me. Thank you! – Yoko Nov 03 '20 at 12:51
  • It's incredible to me that we have to resort to a command like this while we are in a DEV, I repeat, DEV environment. That's where people DEVELOP and frequently will update assets like css etc. Rails should automatically re-compile scss in the dev environmen.. sigh – rails_has_elegance May 28 '21 at 10:59
11

Another technique is to rename the public/assets/ directory to something like public/assets_hide/. Then rename it back before running "rake assets:precompile" and pushing to the server. This cuts down on the precompile time and also preserves the asset file permissions for some gems, like rich, which copies over assets.

An easier way is to modify your config/environments/development.rb file to:

config.serve_static_assets = false

Then you won't need to mess with the public/assets directory. However, if you are using something like paperclip to upload image files, this won't work because the image files won't be served.

Max Dunn
  • 1,244
  • 9
  • 13
4

Probably obvious to everyone, but just wanted to add that if deleting or renaming public/assets/ folder, you'll probably also need to restart your local server and clear browser cache :-)

KevHo
  • 61
  • 2
1

I had the same problem (Ruby 3.0 and Rails 6.1) and I solved it by deleting public/assets/ directory and then running:

$ rake tmp:cache:clear

$ rake assets:precompile
msuliq
  • 150
  • 1
  • 12