2016-03-30 18 views
0

Aşağıdaki yöntemi sahip bir hava API bağlanmak HTTParty taş kullanımı: taş yüklüHTTParty tanımsız yöntemi '+' nil için: NilClass

def weather_search 
    @city_name = params[:city_name] 
    url = URI.encode("api.openweathermap.org/data/2.5/weather?q=#{@city_name}&APPID=#{API_TOKEN}") 
    @search_result = HTTParty.get(url) 
end 

.

ben

beyan aşağıdaki url benim raylar Ancak

api.openweathermap.org/data/2.5/weather?q=banfield&APPID=xxxxxxxxxxxxxxx 

aynı URL hatayı hattında

undefined method '+' for nil:NilClass atar 4 uygulaması ile sorunsuz API ulaşabilir postacı kullanma

@search_result = HTTParty.get(url)

Ben this bulundu ve this other yayınına Konu ama ikisi de yardım etmiyor.

Yığın İzleme: Herhangi bir yardım çok takdir edilecektir

Started POST "/search_city_weather" for 127.0.0.1 at 2016-03-30 23:50:13 +0100 
Processing by WeatherChecksController#weather_search as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "city_name"=>"banfield", "commit"=>"Search"} 
api.openweathermap.org/data/2.5/weather?q=banfield&APPID=xxxxxxxxxxxxxxxxxx 
Completed 500 Internal Server Error in 11ms 
NoMethodError (undefined method `+' for nil:NilClass): 
    app/controllers/weather_checks_controller.rb:24:in `weather_search' 
    Rendered /home/xxxx/.rvm/gems/ruby-2.2.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.3ms) 
    Rendered /home/xxxx/.rvm/gems/ruby-2.2.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.1ms) 
    Rendered /home/xxxx/.rvm/gems/ruby-2.2.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms) 
    Rendered /home/xxxx/.rvm/gems/ruby-2.2.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (22.6ms) 

. Bunu httparty, için geçerli bir URI sunmalıdır @tadman tarafından yazılmış gibi

+1

daha Bu hata diyor? –

+0

Merhaba @BenY Q – JsonP

+4

ana gövdesinde yığın izine bakın. URI'niz neden 'http: //' içermiyor? – tadman

cevap

0

:

  • http://foo.com/resource, çalışacaktır.
  • foo.com/resource, yapmayacaksınız. 0.14.0 daha yeni sürümlerinde arada

, Httparty bu durumlarda, bu hatayı döndürür: URI::InvalidURIError: bad URI(is not URI?):

Çok daha net dan stacktrace ne yapar bu

undefined method '+' for nil:NilClass 
İlgili konular