问题
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.
回答1:
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.
回答2:
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.
回答3:
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 :-)
回答4:
I just want to add something that made the @McFadden suggested a little bit easier to do. Here's what I use:
$ rake tmp:cache:clear && rails server
来源:https://stackoverflow.com/questions/12762939/rails-dev-environment-not-updating-html-css-assets-even-after-restarting-server