[英]Error with Kaminari pagination
我想用 Kaminari 分頁 gem 對我的對象進行分頁。 我的 controller 中有這條線:
@products = Product.order("id").find_all_by_id(params[:id])
在我看來,那條線:
<%= paginate @products %>
我的 model 中的那一行:
paginates_per 20
當我打開應該列出我的對象的頁面時,我收到以下錯誤消息:
undefined method `current_page' for #<Array:0x2964690>
我的<%= paginate @products %>
行引發了異常。
我已經為另一個項目進行了分頁,並且效果非常好。 有人可以幫我嗎?
謝謝 !
編輯:
問題是find_all_by_*
返回一個數組,而不是 ActiveRecord::Relation。
你可以做這樣的事情
@products = Product.order("id").where("id IN (?)", params[:id])
此外,您可能應該在其中有一個.page(params[:page])
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.