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!
Check out this section of the Rails asset pipeline guide for one way to achieve this.
You'll want to move that style rule to the stylesheet for that controller (groups.css.scss
), and then make sure that each page loads the stylesheet associated with its controller. You can do that by adding the following line to your view template (probably application.html.erb
):
<%= stylesheet_link_tag params[:controller] %>
You'll probably also need to then make sure that your css manifest doesn't include groups.css.scss
-- if the rest of your style rules are in application.css
, you can just remove the *= require_tree .
directive.
There are other ways you could do the same thing, so if you're not happy with that approach you should be able to find some other alternatives.