我可以很容易地分頁,但我使用兩個模型,使它複雜一點。未定義的方法`total_pages'爲#<Array:0x8e052a0>,如何正確分頁?
首先,這裏的控制器
class BrowseController < ApplicationController
def index
@hashtags = Hashtag.find(:all, :order => 'created_at DESC')
@posts = post.all
end
end
那麼這裏的視圖(瀏覽\ index.html.erb)
<ul>
<% @posts.each do |post| %>
<% if post.hashtags.present? %>
<li> <%= link_to post.hashtags.map{|h| "##{h.hashtags}"}.join(', '), post.user %> </li>
<% else %>
<% end %>
<% end %>
</ul>
我想分頁這一觀點。這不僅僅是發佈,而是帖子的標籤。什麼是正確的<%= will_paginate %>
代碼?
我正在嘗試分頁帖子的標籤,而不僅僅是帖子本身。
不能分頁數組,唐不要在@posts上調用'.all',否則你將所有的帖子加載到內存中,這種排序方式與使用分頁的全部原因相關 – 2013-05-08 08:58:55
我應該說明你*可以分頁數組,但這不是默認行爲,我用'paginate_array'方法使用kaminari但will_paginate工作方式不同:http://stackoverflow.com/questions/13187076/paginating-an-array-in-ruby-with-will-paginate – 2013-05-08 08:59:45