2011-10-05 48 views

回答

13

在Rails 3.1,如果你的application.css看起来像所有的样式表将被合并到application.css。

您可能需要使用特定的样式表:

*= require main 

否则,你的布局,你写:

%head 
= yield :head 

,并在您的网页:

= content_for :head do 
= stylesheet_link_tag 'stylesheet' 
+0

%head和yield:head bits是做什么的? –

+0

In Haml: %head = yield:head 将在HTML中生成标记,并通过yield从另一页插入代码 – damienbrz

3

参见:
http://guides.rubyonrails.org/layouts_and_rendering.html

(见第2.2.14 '查找布局')

你可以有不同的布局不同的控制器!

例如在应用程序/视图/布局下你可以有application.haml和admin.haml 和应用程序/控制器下你会有一个admin_controller.rb

Rails将尝试找到与控制器同名的布局。

您也可以重写此行为,并指定要使用的布局,例如:

class ItemsController < ApplicationController 
    layout "admin" 
    #... 
end 

你会再根据应用程序创建一个admin.scss文件/样式表为这个新的布局!

/* 
* 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:

+0

+1用于实际指定要查看的部分,而不是转储相同的旧链接。 – ahnbizcad

+0

谢谢。是的,这是一个懒惰的页面,他们改变了节号 – Tilo

10

让我补充一个为我工作的解决方案。

正如在前面的回答中提到,你可能想从application.css文件中删除

*= require_tree . 

声明。

我不停的

*= require_self 

语句在应用程序共享样式。

然后在我的application.html文件我用以下语句,只包括application.css并在视图中controller.controller_name.css样式表。

= stylesheet_link_tag "application", controller.controller_name 
= javascript_include_tag "application", controller.controller_name 

正如你所看到的JavaScript文件的作品一样。

相关问题