views:

31

answers:

1

I use this code to generate the td tag format:

<%= render(:partial => "cart_item", :collection => @cart.items) %>

And this is the _cart_item.html.erb:

<tr>
    <td class="column-left"><%=h cart_item.title %></td>
    <td> x <%= cart_item.quantity %></td> 
    <td class="column-right">$ <%= cart_item.price %></td>
</tr>

But I want to know the row number as well. How can I do?

+3  A: 

I believe you can use cart_item_counter, though I cannot find any documentation to back this up.

Ciarán Walsh
wow, it works, but I would like to know _counter is not a method and attribute, right?
Ted Wong
It’s a variable set by Rails with the same prefix as your item name – e.g. here your items are named `cart_item`, so the counter is `cart_item_counter`.
Ciarán Walsh
wt else variable I can get from Rails?
Ted Wong