What is the difference between content_for and yield?

Technology CommunityCategory: Ruby on RailsWhat is the difference between content_for and yield?
VietMX Staff asked 3 years ago

yield is how you specify where your content areas is going to go within a layout. You might have something like this:

<div>
  <h1> This is the wrapper!</h1>
  <%= yield :my_content %>
</div>

content_for is how you specify which content is going to be rendered into which content area. You might have something like this:

<% content_for :my_content do %>
  This is the content.
<% end %>