在我的索引行動的控制器,我有;問題與分頁和索引行動
def index
@documents = current_user.documents.all if current_user
end
我在current_user的末尾添加的任何內容我遇到一個錯誤。例如,我嘗試添加will_paginate,它只是將.paginate(:per_page => 5, :page => params[:page])
添加到索引操作的末尾,並將<%= will_paginate @documents %>
添加到視圖。
一旦我將.paginate(:per_page => 5, :page => params[:page])
添加到索引方法的末尾,就像這樣;
def index
@documents = current_user.documents.all if current_user.paginate(:per_page => 5, :page => params[:page])
end
我得到一個NoMethodError
。任何人都知道如何解決這個問題?
它的工作原理!那麼沒有.all的問題是否重要? – user1658756
.paginate僅適用於ActiveRecord :: Relation,並且.all將關係轉換爲數組 –
嗯。謝謝! – user1658756