Skip to content

Commit

Permalink
Add collection counters to layouts & rendering guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Gunderloy authored and Mike Gunderloy committed Nov 9, 2008
1 parent 6babecf commit 3baa44a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions railties/doc/guides/html/layouts_and_rendering.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1305,6 +1305,14 @@ <h4 id="_rendering_collections">3.4.5. Rendering Collections</h4>
<pre><tt>&lt;%= render :partial =&gt; "product", :collection =&gt; @products, :as =&gt; :item %&gt; <pre><tt>&lt;%= render :partial =&gt; "product", :collection =&gt; @products, :as =&gt; :item %&gt;
</tt></pre></div></div> </tt></pre></div></div>
<div class="para"><p>With this change, you can access an instance of the <tt>@products</tt> collection as the <tt>item</tt> local variable within the partial.</p></div> <div class="para"><p>With this change, you can access an instance of the <tt>@products</tt> collection as the <tt>item</tt> local variable within the partial.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by <tt>_counter</tt>. For example, if you're rendering <tt>@products</tt>, within the partial you can refer to <tt>product_counter</tt> to tell you how many times the partial has been rendered.</td>
</tr></table>
</div>
<div class="para"><p>You can also specify a second partial to be rendered between instances of the main partial by using the <tt>:spacer_template</tt> option:</p></div> <div class="para"><p>You can also specify a second partial to be rendered between instances of the main partial by using the <tt>:spacer_template</tt> option:</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9 <div class="content"><!-- Generator: GNU source-highlight 2.9
Expand Down Expand Up @@ -1366,6 +1374,11 @@ <h2 id="_changelog">4. Changelog</h2>
<div class="ilist"><ul> <div class="ilist"><ul>
<li> <li>
<p> <p>
November 9, 2008: Added partial collection counter by <a href="../authors.html#mgunderloy">Mike Gunderloy</a>
</p>
</li>
<li>
<p>
November 1, 2008: Added <tt>:js</tt> option for <tt>render</tt> by <a href="../authors.html#mgunderloy">Mike Gunderloy</a> November 1, 2008: Added <tt>:js</tt> option for <tt>render</tt> by <a href="../authors.html#mgunderloy">Mike Gunderloy</a>
</p> </p>
</li> </li>
Expand Down
3 changes: 3 additions & 0 deletions railties/doc/guides/source/layouts_and_rendering.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ When a partial is called with a pluralized collection, then the individual insta


With this change, you can access an instance of the +@products+ collection as the +item+ local variable within the partial. With this change, you can access an instance of the +@products+ collection as the +item+ local variable within the partial.


TIP: Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by +_counter+. For example, if you're rendering +@products+, within the partial you can refer to +product_counter+ to tell you how many times the partial has been rendered.

You can also specify a second partial to be rendered between instances of the main partial by using the +:spacer_template+ option: You can also specify a second partial to be rendered between instances of the main partial by using the +:spacer_template+ option:


[source, html] [source, html]
Expand Down Expand Up @@ -933,6 +935,7 @@ In this case, Rails will use the customer or employee partials as appropriate fo


http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/15[Lighthouse ticket] http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/15[Lighthouse ticket]


* November 9, 2008: Added partial collection counter by link:../authors.html#mgunderloy[Mike Gunderloy]
* November 1, 2008: Added +:js+ option for +render+ by link:../authors.html#mgunderloy[Mike Gunderloy] * November 1, 2008: Added +:js+ option for +render+ by link:../authors.html#mgunderloy[Mike Gunderloy]
* October 16, 2008: Ready for publication by link:../authors.html#mgunderloy[Mike Gunderloy] * October 16, 2008: Ready for publication by link:../authors.html#mgunderloy[Mike Gunderloy]
* October 4, 2008: Additional info on partials (+:object+, +:as+, and +:spacer_template+) by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) * October 4, 2008: Additional info on partials (+:object+, +:as+, and +:spacer_template+) by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication)
Expand Down

0 comments on commit 3baa44a

Please sign in to comment.