I am currently trying to work on a large data set with over 9000 records coming in and would like to paginate it. I have never worked with pagination I know the gems Kaminari and Pagy can do this. I believe I need to wrap my find with either Kaminari supplied methods or Pagy but I am not sure what I am supposed to do with my Jbuilder views after that. Below is a snippet of my find method and a builder for it. The attendees hash has roughly 9000 records causing the load to either time out or take about 5 minutes. I am hoping pagination should smooth this out.
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
Output
{
"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": "[email protected]",
"requires_certification": true
},
{
"full_name": "Bruce Banner",
"email": "[email protected]",
"requires_certification": false
},
{
"full_name": "THor Odinson",
"email": "[email protected]",
"requires_certification": false
}