I want to display my records in multiple rows.
Ex: I am have 10 records and I want to show these records as 3 records in one row, other 3 records in another row and so on.
您可以使用html显示
<tr> </tr>
Try like this:
<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>
Try this, for your solution
Use in-groups-of
For example
<table>
<% @tasks.in_groups_of(4, false) do |row_tasks| %>
<tr>
<% for task in row_tasks %>
<td><%= task.name %></td>
<% end %>
</tr>
<% end %>
</table>
Source :
Suppose you have @articles that has 10 articles then so something like
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.