I ran rake assets:precompile
by mistake on development, and Rails stopped loading the assets on development. I only get application.js
and application.css
loaded.
application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
application.css:
*= require_self
*= require_tree .
Using Rails 3.2.2
Try deleting the compiled assets from your local development environment:
rm -rf public/assets
Edit:
In addition, make sure to set config.assets.compress = false
and config.assets.debug = true
in your development.rb
.
tl;dr
$ rake assets:clean
- restart rails server
$ rails server -e development
- clear browser cache, or do a
ctrl+shift+r
on the app page
Now everything should be as it was before you ran rake assets:precompile
-- end tl;dr --
If the above doesn't work, then a detailed list of steps:
- Do
$ rake assets:clean
or $ rm -rf public/assets
to remove the generated assets.
- In application.rb, ensure:
config.assets.enabled = true
(to enable rails' asset pipleline)
- In development.rb, ensure:
config.assets.compress = false
(so as to not gzip the assets)
config.assets.debug = true
(so as to not merge all css and js files into application.[cs|js])
config.assets.compile = true
(or not set - to enable runtime compilation of assets)
config.serve_static_assets = false
(or not set)
- Finally, restart your rails server
$ rails server -e development
This should fix it.
Running rake assets:precompile
generates static assets under public/assets
which causes Rails to serve these directly. To prevent this you can:
- Manually delete those files or
- Run
rake assets:clean
Open config/application.rb
and set the following:
config.assets.enabled = true
If cleaning your asset directory and ensuring your configuration was correct as indicated by the previous answers did not work - is there a possibility that you're using page caching?
If the page was generated with src
tags pointing to your compiled files, they would need to be regenerated now.
Incase it's helpful to anyone - I had an issue where neither application.js/.css loading in development (I could still see the manifest lines when viewing the source).
I was running an old rails 3.2.2 app for some reason I had to go in and add blank line to both the manifest files (application.js & application.css) and save them - then assets started working properly.
I removed the blank lines and it still worked so I'm assuming perhaps it just needed a newer modified date stamp on the files.