O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test Your Knowledge

Quiz

  1. Where would you put your CSS stylesheet, and how should you connect it to your view?

  2. How does Rails know which layout to apply to a particular view?

  3. What does that yield thing do?

  4. How do I send data from the view template to the layout?

Answers

  1. 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.

  2. 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.

  3. 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.

  4. 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required