ruby-on-rails - 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",
"email": "blank@blank.com",
"requires_certification": false
}
解决方案
推荐阅读
- php - 在 prestashop 1.7 中为每个订单分配订单 ID 而不是订单参考
- asp.net - HTML.TextAreaFor 我需要将日期/时间戳添加到字段中添加的新评论中
- laravel - Laravel 路由正确或更好的方式
- netbeans - “新项目”和“新文件”不起作用
- css - 如何更改选定列闪亮R的背景颜色
- java - 为什么在将数据从活动传递到片段时出现空指针异常?
- javascript - 三元javascript运算符中条件的多个结果
- git - Git diff 两个名称中带有点 (.) 的分支
- jquery - VueJS 和 jQuery 查询选择器
- r - 如果向量的任何值在列表中,则返回 true