Forum: Ruby on Rails how to get the count/index of the current row ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fa11c96121e54b7b02b1b6faf4acd9dc?d=identicon&s=25 Prasanth Satya (prasanth)
on 2006-04-25 05:41
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.
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-04-25 05:54
(Received via mailing list)
On 4/24/06, prasanth satya <j2ee_satya@yahoo.com> 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 %>
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2006-04-25 05:58
(Received via mailing list)
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
Fa11c96121e54b7b02b1b6faf4acd9dc?d=identicon&s=25 Prasanth Satya (prasanth)
on 2006-04-25 06:32
Thank you very much... that worked.
This topic is locked and can not be replied to.