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: parks.limit(per_page).offset((page - 1) * per_page) 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