Add pagination
This commit is contained in:
@@ -1,5 +1,20 @@
|
||||
class Api::V1::ParksController < ApplicationController
|
||||
DEFAULT_PAGE_SIZE = 10
|
||||
|
||||
def index
|
||||
render json: Park.all
|
||||
parks = Park
|
||||
.limit(per_page)
|
||||
.offset((page - 1) * per_page)
|
||||
render json: parks
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def per_page
|
||||
(params[:per_page].presence || DEFAULT_PAGE_SIZE).to_i
|
||||
end
|
||||
|
||||
def page
|
||||
(params[:page].presence || 1).to_i
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user