All threads / PAGY with Rails API Only

Ask A Question

Notifications

You’re not receiving notifications from this thread.

PAGY with Rails API Only

Tim Dowling asked in Rails

Hi All,

I've built a Rails API and have a separate Nuxt/Vue app for my front end. Looking to add server side pagination with Pagy and was wondering how i best to call the next 'X' number of results.

Pagy is working fine and giving me my first 20 records, but to call the next 20 I'm a little confused. Do i need to specify the URL from the front end as in 'localhost:3000/contacts?page=2' and send that, or can i pass some params like [:next] as mentioned in the docs. Has anyone had success with this or has an example?

Cheers

Tim

Hey Tim,

Normally, you want to pass the next page number into the URL like you mentioned. That's how pagination links work when you display render them. Then the server knows which group of 20 records to grab next.

Perfect, thanks for the response Chris. It'll be sinmple to write a ?page=X +1 type method as the page comes in the header of the response. I could also utlise the 'link' from the header.... I'll have a play :)

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.