Add pagination

This commit is contained in:
2025-10-07 22:49:03 -07:00
parent 3c732654d5
commit 7f82574b86
2 changed files with 29 additions and 2 deletions

View File

@@ -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