Wednesday 8 February 2012

WORKING WITH YIELD AND content_for METHOD


Within the context of a layout, yield identifies a section where content from the view should be inserted.


<html>
<head><title>Home Page</title></head>
<body>
  <table width="100%">
    <tr><td>
      <%= yield %>
    </td><td>
      <%= yield :sidebar %>
    </td></tr>
      </table>
  </body>
 </html>
The first yield will be replaced with HOME view when rendered.  The second yield
 is a different: we are passing it a symbol, saying he wants to yield :sidebar
 at that point in time

Now The content_for method allows you to insert content into a named yield block
 in your layout

<% content_for :sidebar do %>
  <title>sidebar</title>
<% end %>

No comments:

Post a Comment