Adding page-specific CSS to Rails Asset Pipeline

后端 未结 5 1391
走了就别回头了
走了就别回头了 2020-12-23 22:52

This is a question that several people have asked before, but none of the questions were quite asked or answered in a way that I found helpful, so I\'m writing the quest

5条回答
  •  别那么骄傲
    2020-12-23 23:05

    Official Solution

    It is documented in the official Rails Guides here: http://guides.rubyonrails.org/asset_pipeline.html#controller-specific-assets

    Actually you can leave out the require_tree directive (located in application.css and application.js) then use this in your template:

    For controller specific JavaScript:

    <%= javascript_include_tag params[:controller] %>
    

    For controller specific CSS:

    <%= stylesheet_link_tag params[:controller] %>
    

提交回复
热议问题