Rails 3.1 Assets - Strange Serving in Development

后端 未结 5 1606
离开以前
离开以前 2020-12-02 09:04

I\'ve got a problem with Rails 3.1 assets pipeline. Assets are included twice in development:



        
相关标签:
5条回答
  • 2020-12-02 09:46

    This just caused me a problem. Setting the following makes the app work but includes the single application.js file - which I don't want in development:

    config.serve_static_assets = false
    

    I had pre-compiled my assets previously (seems to be the cause).

    To fix it I did the following:

    • Remove the public/assets dir that the earlier precompilation had added.
    • Run RAILS_ENV=development rake assets:clean to clear out tmp/assets
    • Edited app/assets/application.js

    It was only after I edited application.js so it errored and then corrected it that the applciation.js included in the pages was not the full, precompiled application.js.

    I'm not sure if all of those need to be done. I was also re-starting my server along the way.

    0 讨论(0)
  • 2020-12-02 09:51

    Got tripped up by this (yet again), -- don't forget to add a BLANK LINE after all your //= require directives at the end of your application.js !

    0 讨论(0)
  • 2020-12-02 09:56

    Once you get rid of /public/assets, you must also clear browser cache.

    0 讨论(0)
  • 2020-12-02 10:06

    I add the same problem with less files.

    Here from the documentation:

    In development mode, assets are served as separate files in the order they are specified in the manifest file.

    My solution was to remove the line *= require_tree . from application.css.less and to only use @import "my-styles"; from less.

    Maybe you can find a similar solution with javascript...

    0 讨论(0)
  • 2020-12-02 10:08

    Try adding the following to development.rb:

    config.serve_static_assets = false
    

    ...and then clearing your browser cache (update based on comments)

    The static assets refer to precompiled assets in public/assets, which is where rake assets:precompile puts them.

    What's happening is that anything that exists in public/assets will override anything in app/assets if you are serving them. So public/assets/application.js is being loaded when the js tag is intending to identifiy app/assets/application.js.

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