# How to get the count/index of the current row?

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712>\
**Category:** Rails\
**Created:** [April 25, 2006, 5:41am UTC](https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712 "2006-04-25T05:41:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@prasanth](https://www.ruby-forum.com/u/prasanth)\
**Post date:** [April 25, 2006, 5:41am UTC](https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712/1 "2006-04-25T05:41:28Z")

</div>

I have a partial to which i pass a collection. That views name is \_row.

So row.name, row.ssn gives me the details of each object in the  
collection,

But i need to display

1. name 123456798
2. name1 234567890

how to get that Index ??? or count or whatever in that partial ??

please help.

---

<div class="post-metadata">

**Author:** ![prasanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@prasanth](https://www.ruby-forum.com/u/prasanth)\
**Post date:** [April 25, 2006, 5:54am UTC](https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712/2 "2006-04-25T05:54:56Z")

</div>

On 4/24/06, prasanth satya [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> how to get that Index ??? or count or whatever in that partial ??
> 
> please help.

render :partial =\> ‘row’, :collection =\> @some\_collection  
…will create a local variable ‘row\_counter’ inside your partial.  
You can then do:  
\<% @row = row -%\>  
\<%= text\_field ‘row’, ‘name’, :index =\> row\_counter %\>

---

<div class="post-metadata">

**Author:** ![prasanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@prasanth](https://www.ruby-forum.com/u/prasanth)\
**Post date:** [April 25, 2006, 5:58am UTC](https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712/3 "2006-04-25T05:58:02Z")

</div>

you can obtain the current index from within the partial by using  
\<partial\_name\>\_counter. ie, if you called your partial via:

render(:partial =\> ‘books’, :collection =\> @book\_list)

you could use books\_counter to retrieve the current index.

Mike

---

<div class="post-metadata">

**Author:** ![prasanth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/87869e/32.png) [@prasanth](https://www.ruby-forum.com/u/prasanth)\
**Post date:** [April 25, 2006, 6:32am UTC](https://www.ruby-forum.com/t/how-to-get-the-count-index-of-the-current-row/58712/4 "2006-04-25T06:32:56Z")

</div>

Thank you very much… that worked.
