简体   繁体   English

如何使用Mongoid扩展will_paginate以实现Rails宝石

[英]How to extend will_paginate for a rails gem with Mongoid

need some help. 需要一些帮助。 I have been updating a gem for a rails forum software. 我一直在更新Rails论坛软件的gem。 It would usually require ActiveRecord but I have converted a majority of the gem to Mongoid. 通常需要ActiveRecord,但我已将大多数宝石转换为Mongoid。

Now here is where I need some help, I am attempting to use will_paginate's per_page method. 现在这是我需要帮助的地方,我正在尝试使用will_paginate的per_page方法。

Here is the code provided. 这是提供的代码。

if defined?(WillPaginate)
module WillPaginate
ActiveSupport.on_load :active_record do
  module ActiveRecord
    module RelationMethods
      alias_method :per, :per_page
      alias_method :num_pages, :total_pages
    end
  end
 end
end

Now the problem is I am using Mongoid, and I am unsure exactly how I would convert this to mongoid. 现在的问题是我正在使用Mongoid,并且我不确定如何将其转换为Mongoid。 If someone could help me I would appreciate that. 如果有人可以帮助我,我将不胜感激。

Resources: 资源:

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

Will_paginate- https://github.com/mislav/will_paginate Will_paginate- https://github.com/mislav/will_paginate

Thanks in advanced! 提前致谢!

For mongoid, you have to user will_paginate_mongoid. 对于蒙古包,您必须使用will_paginate_mongoid。 If that doesn't work, you can look at this cuestion here . 如果那不起作用,您可以在这里查看此提示。 Anyway, just adding will_paginate_mongoid gem to my Gemfile worked for me. 无论如何,仅将will_paginate_mongoid gem添加到我的Gemfile中对我来说是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM