<-- home

rails render partial collection 有 index

例如在view中要遍历@products,代码如下

<%= render partial: "product", collection: @products %>

在_product.html.erb中

<%= product_counter %>

即可输出当前 product 的索引值了