# Is there an implicit index in this loop?

**URL:** <https://www.ruby-forum.com/t/is-there-an-implicit-index-in-this-loop/129084>\
**Category:** Rails\
**Created:** [February 14, 2008, 3:05am UTC](https://www.ruby-forum.com/t/is-there-an-implicit-index-in-this-loop/129084 "2008-02-14T03:05:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 14, 2008, 3:05am UTC](https://www.ruby-forum.com/t/is-there-an-implicit-index-in-this-loop/129084/1 "2008-02-14T03:05:26Z")

</div>

Hi,

I have the partial below …

```
            <% fields_for "ec_order[ec_line_item_attributes][]",

```

ec\_line\_item do |ec\_line\_item\_form| %\>

 Item ####
 \<% end %\>

What I’m wondering is if there’s a way I can substitute the “###” with  
an expression that would list the index of the loop (e.g. “1” would be  
the result for the first iteration, “2” for the second, and so on).

Sure there’s an easy way, just don’t know it.

Thanks, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 14, 2008, 3:22am UTC](https://www.ruby-forum.com/t/is-there-an-implicit-index-in-this-loop/129084/2 "2008-02-14T03:22:26Z")

</div>

On 14 Feb 2008, at 02:04, removed\_email\_address@domain.invalid wrote:

> \<% end %\>
> 
> What I’m wondering is if there’s a way I can substitute the “###” with  
> an expression that would list the index of the loop (e.g. “1” would be  
> the result for the first iteration, “2” for the second, and so on).
> 
> Sure there’s an easy way, just don’t know it.

if you’re rendering a partial foo, then in addition to there being a  
local variable called foo, there’s also one called foo\_counter

Fred
