Add filtering on state
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user