0

In rails3, I want to have all the views in a specific controller(groups_controller) to have a different body background color. I have a stylesheet groups.css with this rule:

body { background-color:#333}

and I'm including this file in application.css. but the problem is now every controller gets the styles I defined in groups.css. Is there another way to do this? Thank you!

4

1 回答 1

1

查看Rails 资产管道指南的这一部分,了解实现此目的的一种方法。

您需要将该样式规则移至该控制器的样式表 ( groups.css.scss),然后确保每个页面加载与其控制器关联的样式表。您可以通过将以下行添加到您的视图模板(可能application.html.erb)来做到这一点:

<%= stylesheet_link_tag params[:controller] %>

您可能还需要确保您的 css 清单不包含groups.css.scss- 如果您的其余样式规则在 中application.css,您可以删除该*= require_tree .指令。

还有其他方法可以做同样的事情,所以如果您对这种方法不满意,您应该能够找到其他替代方法。

于 2013-03-25T00:38:54.530 回答