【问题标题】:Pagination using ROR with mongoid使用 ROR 和 mongoid 进行分页
【发布时间】:2020-05-05 14:03:04
【问题描述】:
class Service 
  include Mongoid::Document 
  include Mongoid::Search 
  include Mongoid::Pagination 
  field :name, type: String
end

我的控制器

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

宝石mongoid-pagination

index.html.erb

<% paginate @services %>

问题

未定义的方法 `total_pages' 用于

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

我需要解决分页问题。

【问题讨论】:

  • 你能分享你的模型代码吗@carlos-lima
  • class Service include Mongoid::Document include Mongoid::Search include Mongoid::Pagination field :name, type: String
  • 如果是测试项目,是否可以提供链接?,您也可以尝试@services = Service.per_page(10)并发布输出。

标签: ruby-on-rails ruby pagination mongoid


【解决方案1】:

我在这里找到的最佳答案: https://stackoverflow.com/a/48287946/1678507

kaminari-mongoid 于 2016 年发布,目前仍在维护中。

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

Kaminiari 对 Mongoid 的所有好处,包括适当的 处理 Mongoid::Criteria 结果,这可能是导致 OP的错误

在 OP 的问题中:

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

【讨论】:

    猜你喜欢
    • 2012-03-27
    • 2012-01-22
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2016-02-09
    • 2014-12-26
    相关资源
    最近更新 更多