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

Want to stay up-to-date with Ruby on Rails?

Join 88,440+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.