Skip to content

Question about passing pagination data when using pagy #356

Answered by okuramasafumi
kinsomicrote asked this question in Q&A
Discussion options

You must be logged in to vote

@kinsomicrote I think your solution is appropriate for now.
It might be a good idea to create a new API to configure pagination though. It might look like below:

class ApplicationSerializer
  include Alba::Resource

  paginate_with(key: :pagination) do |pagy|
    {
      next_page: pagy[:next_url],
      prev_page: pagy[:prev_url],
      prev: pagy[:prev],
      next: pagy[:next],
      from: pagy[:from],
      to: pagy[:to],
      count: pagy[:count]
    }
  end
end

::V1::ApplicantSerializer.new(applicants, {paginate_with: pagy_metadata(pagy)})

This could be more direct and clearer way to configure pagination.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@okuramasafumi
Comment options

Answer selected by kinsomicrote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants