ruby-on-rails-3 – Rails3.1 – 如何在某些视图中包含css文件而不包含其他视图?

似乎在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'

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...