如何解决Rails API模式JBuilder分页
我目前正在尝试处理包含9000条记录的大型数据集,并希望对其进行分页。我从未进行过分页工作,我知道Kaminari和Pagy可以做到这一点。我相信我需要用Kaminari提供的方法或Pagy来包装我的发现,但是我不确定在那之后应该如何处理Jbuilder视图。以下是我的find方法及其构建器的摘要。与会者哈希大约有9000条记录,导致加载超时或耗时约5分钟。我希望分页可以解决这个问题。
Controller
class ConferencesController < ::ApplicationController
def attendees
@conference = Conference.find(attendee_params[:conference_id])
end
private
def attendee_params
params.permit(:conference_id)
end
end
end
View
json.full_name attendee.full_name
json.email attendee.email
json.requires_certification attendee.requires_certification
输出
{
"conference": {
"title": "Avengers Assemble","description": null,"starts_at": "2021-04-21T16:00:00.0000+0000","ends_at": "2021-04-21T16:45:00.0000+0000","attendees_count": 9002
},"attendees": [
{
"full_name": "Steve Rogers","email": "blank@blank.com","requires_certification": true
},{
"full_name": "Bruce Banner","email": "denise.parisian@kirlin.biz","requires_certification": false
},{
"full_name": "THor Odinson","requires_certification": false
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。