Is there any way to get an objects array index as you loop through an array in Ruby?
I'm working with the following code where @ta is set as the array index:This seems very primative to me and prone to errors. Is there anyway to do something like the following:Code:<% @ta=0 %> <% for article in @articles -%> <%= render_partial "article", article %> <% @ta+=1 %> <% end -%>I tried it but got an error.Code:<% for article in @articles -%> <% @ta = article.index %> <%= render_partial "article", article %> <% end -%>




Bookmarks