我想在多行中显示我的记录。
例如:我有 10 条记录,我想将这些记录显示为一行中的 3 条记录,另一行中的其他 3 条记录,依此类推。
假设您有 @articles 有 10 篇文章,那么就像
<div class="articles">
 <% @articles.each_with_index do |article, article_index|%>
    <div class="article" style="float:left">
      <%=article.name%>
    </div>
    <% if (article_index+1) % 3 == 0%>
    <br/> <!-- Or write a div and clear it -->
    <% end %>
 <% end %>
</div>
您可以使用 html 显示
 <tr> </tr>
试试这样:
<table>
<% 
rowCount = 0
@recordsList = Modal.find(:all)
   @recordsList.each do |rec|
      #this will use to make new row.
      if rowCount%3==0
%>
      <tr>
<%    end %>
         <!-- add your records here -->
         <td><%= rec.recordfield %></td>
<%
      rowCount = rowCount + 1
      end
   end
%>
</table>
试试这个,为您的解决方案
使用组内
例如
<table>
  <% @tasks.in_groups_of(4, false) do |row_tasks| %>
    <tr>
      <% for task in row_tasks %>
        <td><%= task.name %></td>
      <% end %>
    </tr>
  <% end %>
</table>
来源: