Rails Layouts and Partials
Layouts allow you to wrap your code in a standard header and footer.
The default layout is called
Any changes we make to this file will be visible in all out views, unless we specify another layout.
Your default layout file lives in
app/views/application.html.erb. Any changes you make to this file will be visible in every page on your site, unless you explicitly use a different layout.
Add a header and footer to your
application.html.erb file. It should be visible on each of your pages.
Passing a title
Try to pass through a
@title variable from the controller to the view. Use this as the page title at the top of your layout file.
Partials are partial views. They allow you to break your code up into smaller sensible chunks.
Partial filenames start with an underscore.
Create a header partial called
Include it in your template using the render method, like so:
<%= render partial: "layouts/header" %>
You may wish to create partials for things like:
- Headers and footers
- Facebook widgets
Create a footer partial now.