Reputation: 353
I have in my database 3 records and i want that they looks like: if I using for (each)
<% @records.each do |record| %>
Upvotes: 7
Views: 3660
Reputation: 77995
Just wrap it in an ol, that way the numbering is dynamic:
<ol>
<% @records.each do |record| %>
<li><%= record %></li>
<% end %>
</ol>
Upvotes: 2
Reputation: 3366
Take a look at each_with_index:
<% @records.each_with_index do |record, index| %>
Upvotes: 1
Reputation: 62027
You probably want each_with_index
. something like:
<% @records.each_with_index do |record, i| %>
<%= (i+1) %>. <%= record.foo %> <br />
<% end %>
Upvotes: 13
Reputation: 10412
you can use each_with_index:
<% @records.each_with_index do |record, i| %>
#your code
<% end %>
Upvotes: 7