2016-03-30 21 views
0

私は次のメソッドを持っている気象APIに接続するためにHTTParty宝石を使用した:宝石がインストールされているHTTParty未定義のメソッド「+」nilのために: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 

。私は、次のURL

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

で問題なくAPIを達することができる郵便配達を使用して

は、しかし、私のレールに4アプリはそれと同じURLは私が

を宣言行にエラー

undefined method '+' for nil:NilClassをスローします

@search_result = HTTParty.get(url)

私は上のthisthis otherポストを見つけました被験者はどちらも助けにはならない。

スタックトレース:

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) 

すべてのヘルプははるかに高く評価されます。あなたがそうhttparty、 のための有効なURIを提供する必要があります@tadmanによって書かれたよう

+1

よりそのエラーは言う? –

+0

こんにちは@BenY Q本体のスタックトレースを参照してください – JsonP

+4

なぜあなたのURIに 'http://'が入っていませんか? – tadman

答えて

0

は:

  • http://foo.com/resource、動作します。
  • foo.com/resource、そうではありません。 0.14.0より新しいバージョンでところで

、 Httpartyな状況で、このエラーを返します: URI::InvalidURIError: bad URI(is not URI?):

はるかに明確からスタックトレースを何本

undefined method '+' for nil:NilClass 
関連する問題