Reputation: 723
I writting a simple app in that an item can have multiple line items. When you go into the items detail view you can see all the line items that belong to it.
I'd like to add a line number to the line_items, when I'm in the item detail view I'd like to see
I was thinking about an autoincrement columns, but this would start from 1 when I reimport the data. So maybe a virtual column, but how would I calculate what to display?
Any ideas?
Thanks Thomas
Upvotes: 0
Views: 85
Reputation: 13675
You could do:
<% line_items.each_with_index do |item, index| %>
<%= render :item_partial, :locals => {:item => item, :index => index} %>
<% end %>
item partial:
<%= index %>. <%= item.name %>
If you want to keep the same order every time, just order your line items by creation date.
Upvotes: 2