Rails render partial counters: displaying a record's index in a collection

I always forget that you can reference the index of an item in a collection when you're using a partial:
<%= render :partial => 'item', :object => @items %>
        # in _item.html.erb
        <%= item_counter %>
This is zero-based, so you might want to +1 if you want the count to start at 1. It's an easy way to number lines in a partial, which I find I do fairly often and I can never remember the syntax for getting that index counter!

Established 2005 · Databasically © 2016