From c3851592a78788cef1129d6bda60831278b0f838 Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Tue, 7 Oct 2025 23:05:12 -0700 Subject: [PATCH] Add filtering on state --- app/controllers/api/v1/parks_controller.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/parks_controller.rb b/app/controllers/api/v1/parks_controller.rb index 7dfa682..b1ee732 100644 --- a/app/controllers/api/v1/parks_controller.rb +++ b/app/controllers/api/v1/parks_controller.rb @@ -2,10 +2,11 @@ class Api::V1::ParksController < ApplicationController DEFAULT_PAGE_SIZE = 10 def index - parks = Park - .limit(per_page) - .offset((page - 1) * per_page) - render json: parks + 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