prasanth satya
2006-Apr-25 03:41 UTC
[Rails] 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. -- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Apr-25 03:54 UTC
[Rails] how to get the count/index of the current row ?
On 4/24/06, prasanth satya <j2ee_satya@yahoo.com> wrote:> 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. >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 On 4/24/06, prasanth satya <j2ee_satya@yahoo.com> wrote:> > 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/cf545e03/attachment.html