This isn’t something that I expected from the asset pipeline.
Let’s say I have a controller called “bugs_controller.rb”. Generating the controller also gives me a stylesheet in the asset pipeline called:
bugs.css.scss
Now, I use simple_form_for in my Rails 3.2.8 application. I want my form elements in this one controller to be laid out with float:le ft, so in bugs.css.scss I put:
.control-group {
float: left;
}
But when I do that, it applies that style to ALL of my views.
That would mean that the Asset Pipeline provides a separation of concerns only for maintenance purposes with respect to CSS. Is this the normal functionality? If so, what is the reasoning behind loading CSS that the user doesn’t need on each page? Or is my application mistakenly loading bugs.css.scss on other views?
Are you loading application.css? If you are and you have this line in there
*= require_tree .
Then all css files in stylesheets folder will be loaded. I’m new to rails 3 and not sure if this would be recommended way to do this but when I need to do what you’re asking, in my layout file, in the head tag after loading css files that need to be loaded everywhere I put
and then in other view that require some other specific css files at the top of the file, I add
Hopefully, this helps.
Or you can always just wrap the form in a container with an id and in css target .control-group for that specific container: