Ruby on rails 显示记录数的时间顺序
在rails中,当显示表记录列表时,我有一列显示每个记录的id(以便查看表中存在多少记录) 唯一的问题是,例如,如果记录编号3被删除,则id也会被删除(由于唯一性) 在查看列表时,是否有方法可以列出1、2、3、4、5等,而不是显示id? 在桌子上 这是我的桌子:Ruby on rails 显示记录数的时间顺序,ruby-on-rails,controller,html-table,Ruby On Rails,Controller,Html Table,在rails中,当显示表记录列表时,我有一列显示每个记录的id(以便查看表中存在多少记录) 唯一的问题是,例如,如果记录编号3被删除,则id也会被删除(由于唯一性) 在查看列表时,是否有方法可以列出1、2、3、4、5等,而不是显示id? 在桌子上 这是我的桌子: <center> <p class="recordnumber"><%= pluralize(@ranches.size, 'Ranch') %> found<p> <
<center>
<p class="recordnumber"><%= pluralize(@ranches.size, 'Ranch') %> found<p>
<%= render :partial => "shared/newlink" %>
<table class="listing" summary="Ranches">
<tr>
<th>#</th>
<th>Ranch Name</th>
<th>Address</th>
<th>Telephone</th>
<th>Actions</th>
</tr>
<% @ranches.each do |ranch| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= ranch.id %></td>
<td><%= ranch.name %></td>
<td><%= ranch.address_line_1 %>,</br><%= ranch.town_city %>,</br><%= ranch.postcode %></td>
<td><%= ranch.telephone %></td>
<td>
<%= link_to("Edit", {:action => 'edit', :id => ranch.id}, :class => 'buttons') %>
<%= link_to("Delete", {:action => 'delete', :id => ranch.id}, :class => 'buttons') %>
</td>
</tr>
<% end %>
</table>
找到
“共享/新链接”%>
#
牧场名称
地址
电话
行动
,
'编辑',:id=>ranch.id},:class=>buttons')%>
'删除',:id=>ranch.id},:class=>buttons')%>
是的。将
每个
替换为每个带有索引的
,如下所示:
<% @ranches.each_with_index do |ranch, i| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= i + 1 %></td>
<td><%= ranch.name %></td>
....
....
之所以存在i+1
,是因为每个索引为
的单位从零开始