The amount of each row.

I have 3 entries in my database, and I want them to look like this: if I use for (each)

<% @records.each do |record| %> 
  • record1
  • record2
  • record3
+6
ruby-on-rails
source share
4 answers

You probably want each_with_index . something like:

 <% @records.each_with_index do |record, i| %> <%= (i+1) %>. <%= record.foo %> <br /> <% end %> 
+12
source share

you can use each_with_index:

 <% @records.each_with_index do |record, i| %> #your code <% end %> 
+6
source share

Just wrap it in ol, so the numbering will be dynamic:

 <ol> <% @records.each do |record| %> <li><%= record %></li> <% end %> </ol> 
+2
source share

Take a look at each_with_index:

 <% @records.each_with_index do |record, index| %> 
+1
source share

All Articles