每行的数量.

Vit*_*off 6 ruby-on-rails

我在我的数据库中有3条记录,我希望它们看起来像:如果我用于(每个)

<% @records.each do |record| %>
Run Code Online (Sandbox Code Playgroud)
  1. RECORD1
  2. RECORD2
  3. RECORD3

Mat*_*eer 12

你可能想要each_with_index.就像是:

<% @records.each_with_index do |record, i| %>
   <%= (i+1) %>. <%= record.foo %> <br />
<% end %>
Run Code Online (Sandbox Code Playgroud)


Mat*_*ani 6

你可以使用each_with_index:

<% @records.each_with_index do |record, i| %>

  #your code

<% end %>
Run Code Online (Sandbox Code Playgroud)