Rails won't load asset pipeline

前端 未结 6 1840
时光说笑
时光说笑 2021-01-18 05:21

I ran rake assets:precompile by mistake on development, and Rails stopped loading the assets on development. I only get application.js and ap

相关标签:
6条回答
  • 2021-01-18 05:31

    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.

    0 讨论(0)
  • 2021-01-18 05:35

    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
    0 讨论(0)
  • 2021-01-18 05:38

    Open config/application.rb and set the following:

    config.assets.enabled = true

    0 讨论(0)
  • 2021-01-18 05:44

    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.

    0 讨论(0)
  • 2021-01-18 05:44

    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.

    0 讨论(0)
  • 2021-01-18 05:46

    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.

    0 讨论(0)
提交回复
热议问题