使用 ROR 和 mongoid 进行分页

Pagination using ROR with mongoid

class Service 
  include Mongoid::Document 
  include Mongoid::Search 
  include Mongoid::Pagination 
  field :name, type: String
end

我的控制器

@services = Service.where(active: true).per_page(10)

gemmongoid-pagination

index.html.erb

<% paginate @services %>

问题

undefined method `total_pages' for

文档 https://github.com/ajsharp/mongoid-pagination

我需要用paginate解决问题。

我在这里找到的最佳答案:

kaminari-mongoid was released in 2016, and is currently maintained.

https://github.com/kaminari/kaminari-mongoid

All the goodness of Kaminiari for Mongoid, including appropriate handling of Mongoid::Criteria results, which was possibly the cause of the OP's error

并且在 OP 问题的上下文中:

Movie.page(2).total_pages #=> 1