reformatted places controller

This commit is contained in:
Aaro Koivukangas
2023-11-13 16:57:29 +02:00
parent b17759ef14
commit 9c7891e11c
3 changed files with 24 additions and 12 deletions
+3 -12
View File
@@ -3,19 +3,10 @@ class PlacesController < ApplicationController
end
def search
api_key = Rails.application.credentials.beermap_api_key
url = "http://beermapping.com/webservice/loccity/#{api_key}/"
response = HTTParty.get "#{url}#{ERB::Util.url_encode(params[:city])}"
places_from_api = response.parsed_response["bmp_locations"]["location"]
if places_from_api.is_a?(Hash) && places_from_api['id'].nil?
redirect_to places_path, notice: "No places in #{params[:city]}"
@places = BeermappingApi.places_in(params[:city])
if @places.empty?
redirect_to places_path, notice: "No locations in #{params[:city]}"
else
places_from_api = [places_from_api] if places_from_api.is_a?(Hash)
@places = places_from_api.map do |location|
Place.new(location)
end
render :index, status: 418
end
end