2012-11-22 73 views
1

我想在多行中顯示我的記錄。顯示多行記錄?

例如:我有10條記錄,我想將這些記錄顯示爲一行3記錄,其他3行記錄顯示在另一行等等。

+0

當你說一排你的意思是一個錶行? –

+0

在HTML中使用表格.....它將幫助 –

回答

0

嘗試這樣的:

<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> 
+0

感謝您的幫助。它的工作正常。 – Sunny

0

假設你有一個具有@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> 
+0

感謝您的幫助。它的工作正常。 – Sunny