Without any arguments, revenue will display the current controller / action template. Therefore, if you are on the cars/show page, it will display views/cars/show.html.erb .
When you pass the yield argument, it allows you to define content in your templates that you want to display outside of that template. For example, if your cars/show page contains a specific html fragment that you want to render in the footer, you can add the following to your show template and the car_general layout:
show.html.erb:
<% content_for :footer do %> This content will show up in the footer section <% end %>
layouts / car _general.html.erb
<%= yield :footer %>
The Rails Guide has a good section on using yield and content_for: http://guides.rubyonrails.org/layouts_and_rendering.html#understanding-yield
The API documentation for content_for also useful and has some other examples. Note that this is for Rails 3.1.1, but this functionality has not changed much since 2.3, if at all, and should still apply for 3.0.x and 3.1.x.
Peter Brown Oct. 21 '11 at 10:28 2011-10-21 10:28
source share