Tuesday, November 9, 2010

"Show more" - hide higher index items when rendering a collection

While rendering a collection, I wanted to hide some items with higher indexes (and show them when clicking on "Show more"). But there is no way to tell the index when rendering :collection => @items. Then I came across this posting:

Render partial with collection has hidden counter

Now, when rendering
<ul>
<%= render :partial => 'item', :collection => @items %>
</ul>


I can have the partial where only 3 items are shown:
<li style="<%= (item_counter + 1 > 3) ? 'display:none' : '')">item.name</li>

No comments:

Post a Comment