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

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.

On 4/24/06, prasanth satya [email protected] 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 %>

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

Thank you very much… that worked.