Table of Content
Using partial file
View filename that starts with underscore are called partial:
- _form.html.erb
- _nav.html.erb
When using render
function, we specify the partial name without the underscore:
<%= render 'nav' %>
If the partial file is not in the same folder, say views/layouts/_nav.html.erb
, we can include the path.
<%= render 'layouts/nav' %>
Sometimes we need to pass variable into partial. We can do that by specifing the locals.
<%= render partial: 'layouts/nav', locals: {key: 'value'} %>
What’s next? We’re going to take a look at “Dynamic title with content for”.