I read that the following line in application.css includes all the css files in the tree
*= require_tree .
My confusion is that, from what I have found out (please correct me if I am wrong), I need to add the following line into my application.haml if I want css files to load when they match with the controller rendering them:
= stylesheet_link_tag params[:controller]
Doubt1: Do I really need to add this line? I thought it was done automatically by convention. (I am guessing the answer to this is yes, I need to include this line)
Doubt2: Since the application.css loads all the css files due to "require_tree .", would cause some kind off conflicts/messing about with each of the other css files?
Doubt3: What if I wanted to use the require_tree to load all of the skeleton files in that directory, and when a screen renders, to load in particular the controller css.
For example,
I have:
- application.css
- some_basic_styling.css
- home.css.scss
- invitation.css.scss
My application.css would include all of the css files (due to require_tree). The home.css is meant to load by the home controller, and the invitation.css is supposed to be loaded by the invitation controller. What steps do I need to ensure this?
In Rails 3.1 with asset pipeline there's a default sprocket command
require_tree .
that loads all the files in app/assets/stylesheets/ and compiles it into application.css.The
= stylesheet_link_tag params[:controller]
command basically outputs this into your views.= stylesheet_link_tag :products
if viewing from the products controller.This is not needed to get all the files to be compiled into application.css. All files are automatically compiled into application.css by default.
The use case of requiring a stylesheet per a controller is if you don't
require_tree .
. Basically, you don't want everything compiled in one stylesheet. It's the opposite of the default.