Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Using Partials.docx58.8 KB Using Partials - Solution.docx
58.9 KB
Quick reference
Using Partials
In this video, we'll learn how and why to use partials.
When to use
Partials are especially useful when you have a block of code that you would like to separate out from other code. It keeps the original file clean and easy to read.
Instructions
To create a navbar partial, add a file to your app/views/home directory named _navbar.html.erb
Be sure to always name a partial with a preceding underscore _
To call a partial, use the following embedded Ruby code:
<%= render 'home/navbar' %>
Hints & tips
- Partial files should always be named with a preceding underscore ( _navbar.html.erb)
- <%= render 'home/navbar' %>
- Notice the 'home/navbar' text is NOT 'home/_navbar' even though we named our partial file _navbar.html.erb
Lesson notes are only available for subscribers.