显示表RoR

时间:2016-02-13 23:47:31

标签: ruby-on-rails ruby

我是RoR的新手。我正在制作一个包含文章标题和文章文本的文章表。我在桌子上展示它。到现在为止还挺好。我接下来要做的是在表格中显示ROW NUMBER。 这是我的代码:

  <table>
  <tr>
here-> <th> RowNum </th>
    <th>Title</th>
    <th>Text</th> 
</tr>

<% @articles.each do |article| %>
<tr>
    <td> <%= article.title %></td>
    <td> <%= article.text %></td>   
</tr>
<% end %>
</table>

我试过用$。 magich变量和$ INPUT_LINE_NUMBER它不起作用。

1 个答案:

答案 0 :(得分:4)

使用@articles.each_with_index do |article, index|

然后在表格中添加<%= index %>