Topic: get array count

while iterating through an instance variable, is there a way to get the "count" while in the for loop without a temporary variable?


Re: get array count

Try each_with_index if the instance variable is an array:

<% @items.each_with_index do |item, index| %>
  <%= index+1 %>.
  <%= %>
<% end %>

Add one to the index if you need it to start at 1.

Railscasts - Free Ruby on Rails Screencasts

Re: get array count

cracking! thanks.