22 lines
454 B
Ruby
22 lines
454 B
Ruby
class Api::V1::ParksController < ApplicationController
|
|
DEFAULT_PAGE_SIZE = 10
|
|
|
|
def index
|
|
parks = Park.all
|
|
if params[:state].present?
|
|
parks = parks.where("states like '%' || ? || '%'", params[:state])
|
|
end
|
|
render json: parks.limit(per_page).offset((page - 1) * per_page)
|
|
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
|