Rails won't load asset pipeline

倾然丶 夕夏残阳落幕 提交于 2019-12-30 18:26:23

问题


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


回答1:


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.




回答2:


tl;dr

  1. $ rake assets:clean
  2. restart rails server $ rails server -e development
  3. 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:

  1. Do $ rake assets:clean or $ rm -rf public/assets to remove the generated assets.
  2. In application.rb, ensure:
    • config.assets.enabled = true (to enable rails' asset pipleline)
  3. 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)
  4. Finally, restart your rails server $ rails server -e development

This should fix it.




回答3:


Running rake assets:precompile generates static assets under public/assets which causes Rails to serve these directly. To prevent this you can:

  1. Manually delete those files or
  2. Run rake assets:clean



回答4:


Open config/application.rb and set the following:

config.assets.enabled = true




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/16020842/rails-wont-load-asset-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!