From 222477d51ee01699a9b1121dcf66c442f599ab33 Mon Sep 17 00:00:00 2001 From: Bohung Date: Fri, 19 Nov 2021 08:20:51 +0800 Subject: [PATCH] Fix bug. --- app/models/ruling_weather_setting.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/ruling_weather_setting.rb b/app/models/ruling_weather_setting.rb index b313656..34eb232 100644 --- a/app/models/ruling_weather_setting.rb +++ b/app/models/ruling_weather_setting.rb @@ -54,8 +54,8 @@ class RulingWeatherSetting url2 = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0002-001.json" res2 = Net::HTTP.get_response(URI.parse("#{url2}?#{data2.to_query}")) content2 = JSON.parse(res2.body) - weather_data2 = get_weather_data(content2) - rain = weather_data2["NOW"]["elementValue"].to_f + weather_data2 = get_weather_data(content2) rescue {} + rain = weather_data2["NOW"]["elementValue"].to_f rescue 0.0 end result = {"mint" => mint, "maxt" => maxt, @@ -86,7 +86,7 @@ class RulingWeatherSetting "locationName" => custom_location} res = Net::HTTP.get_response(URI.parse("#{url}?#{data.to_query}")) content = JSON.parse(res.body) - weather_data = get_weather_data(content) + weather_data = get_weather_data(content) rescue {} end def get_weather_data(content) if content["records"]["locations"]