Skip to content Skip to sidebar Skip to footer

Display Chronological Order Of Number Of Records

In rails when displaying a list of table records, I have a column which displays the id of each record (so as to see how many records exist in the table) The only problem is for ex

Solution 1:

Yes. Replace each with each_with_index like this:

<% @ranches.each_with_indexdo |ranch, i| %>
   <trclass="<%= cycle('odd', 'even') %>"><td><%= i + 1 %></td><td><%= ranch.name %></td>
....

The i + 1 is there because each_with_index starts at zero.

Post a Comment for "Display Chronological Order Of Number Of Records"