简体   繁体   English

Rails 3分页,will_paginate与Kaminari

[英]Rails 3 pagination, will_paginate vs. Kaminari

My setup: Rails 3.0.9, Ruby 1.9.2 我的设置:Rails 3.0.9,Ruby 1.9.2

I'm looking into a pagination solution for my app and saw that there is a new-ish gem Kaminari compared to the trusty will_paginate . 我正在研究我的应用程序的分页解决方案,并看到有一个新的宝石Kaminari与可信赖的will_paginate相比。 It looks like will_paginate wasn't updated for awhile but has since came back with V3.0. 看起来will_paginate暂时没有更新,但后来又回到了V3.0。 What's the consensus, is one preferred over the other and why? 什么是共识,是一个优先于另一个,为什么? Thanks in advance for your insights. 提前感谢您的见解。

EDIT 编辑

I asked Ryan Bates on Twitter and he said 我在推特上问赖恩贝茨,他说

Both do the job equally well. 两者都做得很好。 The biggest factor is if you use any gems which require pagination since they are incompatible. 最重要的因素是如果你使用任何需要分页的宝石,因为它们是不兼容的。 I do like will_paginate's non-engine approach a bit more, but that's a personal preference. 我更喜欢will_paginate的非引擎方法,但这是个人偏好。

Kaminari Rocks if you are using rails 3+ , I like to use it because Kaminari Rocks,如果你使用rails 3+,我喜欢使用它,因为

  1. It is latest library and supports rails 3+ powerfully. 它是最新的库,强大支持rails 3+。
  2. 'Kaminari' is Easy to use and it supports ajax very easily. 'Kaminari'易于使用,它非常容易支持ajax
  3. Paginate pure Object way. Paginate纯对象方式。
  4. It works as a proxy on AREL, no specific paginate method overloaded on ActiveRecord 它作为AREL的代理,没有在ActiveRecord上重载的特定paginate方法
  5. Does not pollute the Array or Hash object 不污染Array或Hash对象
  6. More standard rails support for other view formats, most important mobile 更多标准轨道支持其他视图格式, 最重要的移动设备

     User.page(7).per(50) 

    But if you are using rails 2.3 etc. keep stick with will_paginate that also works with rails 3 +, but internally its not such perfect as Kaminari code. 但是如果你使用的是rails 2.3等,请坚持使用也适用于rails 3 +的will_paginate ,但在内部它并不像Kaminari代码那样完美。

I really like Kaminari. 我真的很喜欢Kaminari。 I don't know if will_paginate does this, but Kaminari also can paginate any regular old Array : 我不知道will_paginate是否会这样做,但是Kaminari也可以对任何常规的旧Array进行分页:

Kaminari.paginate_array(an_array).page params[:page]

There are Railscasts for both, which I recommend watching. 两者都有Railscasts ,我建议观看。

watch the kaminari railscast an then watch the will paginate railscast 观看kaminari轨道广播 ,然后观看意志分页轨道广播

Ryan Bates advises in the comments that Kaminari makes heavier use of partials, which might make it fractionally slower, but not much Ryan Bates在评论中建议Kaminari更多地使用偏见,这可能会使它稍微慢一些,但不会太多

I have used both Gems, and frankly, I like Kaminari better. 我使用过两种宝石,坦率地说,我更喜欢Kaminari。 It's so easy to use. 它很容易使用。 I haven't seen any performance issues or environment issues (my app lives on Heroku). 我没有看到任何性能问题或环境问题(我的应用程序存在于Heroku上)。

While will_paginate does the job pretty quickly, Kaminari also allow you to quickly edit the pagination HTML output. 虽然will_paginate可以很快完成工作,但Kaminari还允许您快速编辑分页HTML输出。

This was a great thing for me, since i am using Bootstrap 3, and wanted to use the default paginations styles. 这对我来说是件好事,因为我使用的是Bootstrap 3,并且想要使用默认的paginations样式。

There is a gem for will_paginate that allows you to do the same, but Kaminari it's much more flixible will_paginate有一个宝石可以让你做同样的事,但是Kaminari它更加灵活

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

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