开发者

How to add line number in a rails app?

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

  1. line_item_1
  2. line_item_1
  3. line_item_1

I was thinking about an autoincrement columns, but this wo开发者_StackOverflowuld 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜