似乎在rails 3.1中,所有css.scss文件都合并为1个文件.如果我想将css文件仅包含在某些视图中,该怎么办?就像我想要管理页面中包含admin.css.scss和home / about / contact页面中的main.css.scss一样.
解决方法
在Rails 3.1中,如果application.css如下所示,所有样式表将合并到application.css中:
/* * This is a manifest file that'll automatically include all the stylesheets available in this directory * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at * the top of the compiled file,but it's generally better to create a new file per style scope. *= require_self *= require_tree . */
这是由于* = require_tree.
您可以要求特定的样式表:
*= require main
否则,在您的布局中,您写道:
%head = yield :head
并在您的页面中:
= content_for :head do = stylesheet_link_tag 'stylesheet'