From 5dd2814f88724259d99ecc472b5a5daf90a3d3cb Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Tue, 7 Oct 2025 23:16:21 -0700 Subject: [PATCH] Add ParksController show action --- app/controllers/api/v1/parks_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/api/v1/parks_controller.rb b/app/controllers/api/v1/parks_controller.rb index b1ee732..486d1a9 100644 --- a/app/controllers/api/v1/parks_controller.rb +++ b/app/controllers/api/v1/parks_controller.rb @@ -1,5 +1,6 @@ class Api::V1::ParksController < ApplicationController DEFAULT_PAGE_SIZE = 10 + before_action :set_park, only: :show def index parks = Park.all @@ -9,6 +10,10 @@ class Api::V1::ParksController < ApplicationController render json: parks.limit(per_page).offset((page - 1) * per_page) end + def show + render json: @park + end + private def per_page @@ -18,4 +23,9 @@ class Api::V1::ParksController < ApplicationController def page (params[:page].presence || 1).to_i end + + def set_park + @park = Park.find_by(code: params[:code]) + head :not_found unless @park.present? + end end