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


#1

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.


#2

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


#3

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


#4

Thank you very much… that worked.