Asset Pipeline: excluding an admin.css file

后端 未结 4 1585
北海茫月
北海茫月 2021-02-05 03:55

I upgraded a Rails 3.0 app to Rails 3.1 which involved putting this

/*
*= require_self
*= require_tree .
*/

in the application.css file. Howeve

相关标签:
4条回答
  • 2021-02-05 04:21

    You can use the stub sprockets' directive in your manifest like this :

    /*
    *= require_self
    *= require_tree .
    *= stub admin
    */
    

    This will exclude admin.css and also ALL css required in it !! So, if your admin.css's manifest seems like this :

    /*
    *= require bootstrap
    *= require_self
    */
    

    the bootstrap.css will also be excludes and no require could fixe this ! Take care of this ;)

    0 讨论(0)
  • 2021-02-05 04:22

    Similar question was asked earlier and you should check that one.

    Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain directives — instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if Rails.application.config.assets.compress is true). By serving one file rather than many, the load time of pages can be greatly reduced because the browser makes fewer requests.

    You can have as many manifest files as you need. For example the admin.css and admin.js manifest could contain the JS and CSS files that are used for the admin section of the application.

    In particular, you can specify individual files and they are compiled in the order specified.

    Example and more details can be found in this guide.

    Thus, your new application.css would become:

    /*
     *= require styles
     *= require layout
     */
    
    /* Other styles */
    
    0 讨论(0)
  • 2021-02-05 04:22

    Another solution is to have two directories in app/assets/stylesheets, for example, a public directory and an admin directory.

    Then, in app/assets/stylesheets/application.css, you can change require_tree . to require_tree ./public.

    You might have to do something similar on the admin side. I happen to be using the Administrate gem which knows where to find its own assets.

    0 讨论(0)
  • 2021-02-05 04:23

    soluction is add in config/assets.rb

    #config/assets.rb
    Rails.application.config.assets.precompile  += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico *.swf *.xap masonry.pkgd.min.js jquery.colorbox-min.js i18n/jquery.colorbox-pt-BR.js admin.css)
    

    And Add in app/views/layouts/_adm_layout.html.erb

    #app/views/layouts/_adm_layout.html.erb
    <%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track' => true %>
    
    0 讨论(0)
提交回复
热议问题