Add filtering on state

This commit is contained in:
2025-10-07 23:05:12 -07:00
parent d0a517a3d4
commit c3851592a7

View File

@@ -2,10 +2,11 @@ class Api::V1::ParksController < ApplicationController
DEFAULT_PAGE_SIZE = 10 DEFAULT_PAGE_SIZE = 10
def index def index
parks = Park parks = Park.all
.limit(per_page) if params[:state].present?
.offset((page - 1) * per_page) parks = parks.where("states like '%' || ? || '%'", params[:state])
render json: parks end
render json: parks.limit(per_page).offset((page - 1) * per_page)
end end
private private