我想知道是否有一種方法來完成這個黑客,我正嘗試使用我的Ruby on Rails應用程序。我遇到了一些關聯問題,找不到解決方案。你可以see that question here。尋找一個短期修復限制記錄顯示數量沒有:限制=> 10
在平均時間,我想記錄的顯示限制到一些像10
但我不希望通過:limit => 10
的方式做到這一點的控制器,因爲我經歷了所有的記錄,需要循環。我甚至不確定這是否可能,但我想我會問。
我的看法代碼:
<% @comments.each do |comment| %>
<% if comment.workout.user_id == current_user.id %><br/>
<%= link_to (comment.user.username), comment.user %> <br/>
<%= time_ago_in_words(comment.created_at) %> <br/>
<%= link_to (comment.workout.title), comment.workout %><br/>
<%= sanitize(simple_format(comment.body), :tags => %w(p)) %>
<% end %>
<% end %>
我控制器簡單地調用
@comments = Comment.all(:order => "created_at DESC")
當你的意思是你需要遍歷所有記錄,你的意思是在控制器? – 2010-11-30 18:49:53