X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/f7f2b7482d7bcfc7905746cee650ceb51c4e8e01..7f92d533d00c83c653322aae60413ccbbd36e10d:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8444311b5..4ce31baf4 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -1,28 +1,17 @@ class GeocoderController < ApplicationController layout 'site' + require 'uri' require 'net/http' require 'rexml/document' def search - - if params[:postcode] - unless params[:postcode].empty? - postcode = params[:postcode] - check_postcode(postcode) - return - end - end - if params[:query][:postcode] - unless params[:query][:postcode].empty? - postcode =params[:query][:postcode] - check_postcode(postcode) - return - end - end - if params[:query][:place_name] - @place_name = params[:query][:place_name] - redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => @place_name} + if params[:postcode] and not params[:postcode].empty? + check_postcode(params[:postcode]) + elsif params[:query][:postcode] and not params[:query][:postcode].empty? + check_postcode(params[:query][:postcode]) + elsif params[:query][:place_name] + redirect_to :controller => 'geocoder', :action => 'results', :params => {:place_name => params[:query][:place_name]} end end @@ -122,7 +111,7 @@ class GeocoderController < ApplicationController @res_ary = [] begin Net::HTTP.start('ws.geonames.org') do |http| - res = http.get("/search?q=#{@place_name}&maxRows=10") + res = http.get("/search?q=#{URI.escape(@place_name)}&maxRows=10") xml = REXML::Document.new(res.body) xml.elements.each("geonames/geoname") do |ele| res_hash = {} @@ -134,9 +123,12 @@ class GeocoderController < ApplicationController @res_ary << res_hash end end - rescue - #Flash a notice to say that geonames is broken - redirect_to "/index.html" + + flash.delete(:notice) + rescue Timeout::Error + flash[:notice] = "Timed out waiting for results from ws.geonames.org" + rescue Exception => ex + flash[:notice] = "Error contacting ws.geonames.org: #{ex.to_s}" end end end