30 lines
645 B
Ruby
30 lines
645 B
Ruby
module Api::V1
|
|
class ParksController < BaseController
|
|
before_action :set_park, only: :show
|
|
|
|
def index
|
|
parks = Park.all
|
|
if params[:state].present?
|
|
parks = parks.where("states like '%' || ? || '%'", params[:state])
|
|
end
|
|
render json: {
|
|
total: parks.count,
|
|
limit: pagination_limit,
|
|
offset: pagination_offset,
|
|
parks: parks.limit(pagination_limit).offset(pagination_offset)
|
|
}
|
|
end
|
|
|
|
def show
|
|
render json: @park
|
|
end
|
|
|
|
private
|
|
|
|
def set_park
|
|
@park = Park.find_by(code: params[:code])
|
|
head :not_found unless @park.present?
|
|
end
|
|
end
|
|
end
|