New Discussion

Notifications

You’re not receiving notifications from this thread.

How to implement cursor based pagination

0
Rails

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:

  1. In show.html.erb place last_record_id and has_more data attributes.
  2. If has_more is true and scroll in top position, send message to channel
  3. After receiving message from channel append data before current messages.
  4. 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.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.