对于 Ruby on Rails,当从 API 获取数据时如何使用 will_paginate 或 Kaminari? (通过网络)
看起来 will_paginate 和 Kaminari 都与 ActiveRecord 紧密相关?如果通过API获取数据,那么
http://www.foo.com/fetch_data?type=products&offset=100&count=20
如何使用will_paginate或Kaminari来进行分页呢?如果不能,是否有其他分页解决方案可以在这种情况下工作?
It seems like will_paginate and Kaminari are both very tied into ActiveRecord? If the data is obtained through an API, such as
http://www.foo.com/fetch_data?type=products&offset=100&count=20
then how can you use will_paginate or Kaminari to do the pagination? If cannot, is there other pagination solution that can work in this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经为我的acts_as_indexed 插件在非AR 集上进行了分页。
在您的情况下,它的工作方式如下:
控制器:
视图:
填写您自己的方法来获取和处理数据,并计算出总条目。
I already do pagination on a non-AR set for my acts_as_indexed plugin.
In your case it would work something like the following:
Controller:
Views:
Fill in your own methods for fetching and processing the data, and working out the total entries.
我编写了自己的函数来对对象数组进行分页。您可以修改代码以满足您自己的需要:
I wrote my own function to paginate an array of objects. You can modify the code to suit your own needs: