How to implement cursor based pagination
Hi! I'm new to RoR. Followed Chat Series and want to improve it using infinite scroll. When user reaches top of box I want to load older messages.
Should I use channels to send request for messages to be appended?
GitHub is using cursor pagination in repositories
tab. For example: https://github.com/danikarik?after=Y3Vyc29yOnYyOpK5MjAxOS0wNy0xMFQxNzo0OTo0NyswNjowMM4LsayS&tab=repositories
Is it possible to do like that:
- In
show.html.erb
placelast_record_id
andhas_more
data attributes. - If
has_more
is true and scroll in top position, send message to channel - After receiving message from channel append data before current messages.
- Update data attributes.
I don't know how to do in best way. Should I extend application_controller or application_record? How to make it reusable?
How to hash cursor like GitHub did.