Answer the question
In order to leave comments, you need to log in
How to write pagination using limit and offset?
There is an API written in RoR using the Grape gem.
Looks like this:
class V1::Authenticated::PlanActions < Grape::API
resource :tickets do
get serializer: TicketSerializer do
available_tickets = Base.accessible_by(@ability).map(&:id)
ticket = Ticket.where(available_tickets_id: available_tickets)
ticket
end
end
end
[
{
"name": "MP-3",
"updated_at": "2019-06-19T14:18:27.371Z",
"review_status": "Not Started"
},
{
"name": "Co-1",
"updated_at": "2019-06-19T14:40:55.372Z",
"review_status": "Complete"
},
{
"name": "",
"updated_at": "2019-06-20T12:31:54.534Z",
"review_status": "In Progress"
},
{
"name": "CB-4e",
"updated_at": "2019-06-20T12:37:46.838Z",
"review_status": "Complete"
},
{
"name": "Coun62",
"updated_at": "2019-06-20T13:30:47.673Z",
"review_status": "Not Started"
},
{
"name": "5556jjj",
"updated_at": "2019-06-20T13:43:12.527Z",
"review_status": "Not Started"
}
]
params[page, per_page]
Answer the question
In order to leave comments, you need to log in
Ticket.limit(params[:per_page]).offset((params[:page].to_i - 1) * params[:per_page])
Read any articles and see any example on the topic "writing a blog on %langname%" or in Google "%database name% pagination"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question