I am following this tutorial http://guides.rubyonrails.org/layouts_and_rendering.html and trying to separate the header div from the rest of the HTML templates.
I have taken out a div from my app/views/home/index.html.erb file and replaced it with
<%= yield :head %>
Then I made a file called head.html.erb in the /app/views/layouts directory and put that div in there. Then I put this code around the div:
<% content_for :head do %>
<% end %>
But it doesn’t work and the header div does not get displayed. Where did I go wrong? I think there is a path and directory mismatch, but I am not sure exactly how to match them up.
Thank you!
Your layout is where you put the
yieldcall, and each view’s template is where you put thecontent_forblock. You’ll probably want youryieldcall in your application’s main layout file.So in
app/views/layouts/application.html.erbput this where you want it to be:Then in each view, you can do this:
And it will insert inside the div in your layout file.