用 kaminari 和 mongoid 分页

pagination with kaminari and mongoid

我有这个问题

undefined method `total_pages' for
# <Mongoid::Criteria:0x00000002651d80>

# controller
@services = Service.paginate(:page => params[:page], :per_page => 3)

# view
<% paginate @services %>

mongo 不是 return 对象。

控制器

class ServicesController < ApplicationController
 def index
  #@services = Service.order(name: :asc)
  @organs = Admin::Organ.all
  @services = Service.paginate(:page => params[:page], :per_page => 3)
 
 end
end

<% pagination @services %>
错误

undefined method `total_pages' for #<Mongoid::Criteria:0x00000002651d80>

这是

在 kaminari,你必须 使用以下语法

 Service.page(params[:page].to_i).per(3)

而不是

 Service.paginate(:page => params[:page], :per_page => 3)

这是will_paginate

的语法