Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 显示记录数的时间顺序_Ruby On Rails_Controller_Html Table - Fatal编程技术网

Ruby on rails 显示记录数的时间顺序

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> <

在rails中,当显示表记录列表时,我有一列显示每个记录的id(以便查看表中存在多少记录) 唯一的问题是,例如,如果记录编号3被删除,则id也会被删除(由于唯一性)

在查看列表时,是否有方法可以列出1、2、3、4、5等,而不是显示id? 在桌子上

这是我的桌子:

  <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
,是因为
每个索引为
的单位从零开始