Where would you put your CSS stylesheet, and how should you connect it to your view?
How does Rails know which layout to apply to a particular view?
What does that yield
thing do?
How do I send data from the view template to the layout?
Stylesheets go in the public/stylesheets directory, and you
connect them to your views (or layouts) by putting a call to
stylesheet_link_tag
in the head
element.
By default, Rails will apply the layout in app/views/layout/application.html.erb to all of your views. However, if there is a layout file in app/views/layout/ that has the same name as a view, Rails will use that instead.
The yield
method hands control to a different block of code,
one that was passed with parameters. Rails often handles this
quietly, making it easy to share data between, for example,
layouts and views.
The layout has access to all of the same variables the view uses. You don’t need to do anything special to pass variables to the layout, even if you want the layout to apply them early in your HTML document.