Ruby on Rails Views Replace HTML code in Views


If you ever wanted to determine the html content to be printed on a page during run time then, rails has a very good solution for that. It has something called the content_for which allows us to pass a block to a rails view. Please check the below example,

Declare content_for

  <%= yield :header %>

<% content_for :header do %>
   <li>Line Item 1</li>
   <li>Line Item 2</li>
<% end %>