6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/pattana/api/v1/regions_controller.rb', line 6
def index
proc_code = Proc.new do
@country = Country.find_by_id(params[:country_id])
if @country
@relation = @country.regions.includes(:country).show_in_api(true).order("regions.name ASC")
@relation = @relation.search(params[:q]) if params[:q]
@relation = @relation.operational(true) if params[:operational] && ["y","t","yes","true",1].include?(params[:operational].downcase)
@regions = @relation.all
@data = ActiveModelSerializers::SerializableResource.new(@regions, each_serializer: RegionPreviewSerializer)
@success = true
else
@success = false
@errors = {
heading: I18n.translate("api.regions.country_not_found.heading"),
message: I18n.translate("api.regions.country_not_found.message")
}
end
end
render_json_response(proc_code)
end
|