The view helper method capture provides this functionality to wrap a section of the view template in a variable and can be used multiple times in the view.
<% @message = capture do %> You can earn a lot, if you use your brain! <%= link_to "Click here", earning_url %> to know more! <% end %>
If its needed to render a section of template code, we usually go with partials. Capture is specifically useful when partial is only going to be used in just one view template. As there will be this variable available throughout the template, we can use it as many times as needed instead of partial.