check out my new blog at gmarik.info/blog

Sunday, September 02, 2007

Rails: collection index within partial render

Tonight i've found a tiny and nice feature i was missing sometimes...(in order to have it created custom helper)

So when you have:
.rhtml:

<ul>
<%= render :partial => 'games/game', :collection => @games %>
</ul>


you may sometimes need to access collection index. And you can easily do that by using local variable named by such convention <partial_name>_counter
Like this:

.rhtml:

<li> <%= game_counter %> item
</li>


PS. and yes you can always use ordered(numbered)lists(ol instead ul)

0 Comments:

Post a Comment

<< Home