【发布时间】:2014-11-28 17:54:22
【问题描述】:
下面是获取天气的非常简单的 Ruby 代码。我是第一次尝试 Rails,很难将 ruby 代码添加到我的 pages_controller.rb
我的问题是如何最好地将代码添加到我的控制器中。
我还没有看到任何简单地分解这一点的教程。感谢任何帮助/示例。
def your_destination
puts "Where are you going?"
@trip_destination = gets.chomp
HTTParty.get("http://api.wunderground.com/api/#######key######/geolookup/conditions/q/#{@trip_destination}.json")
end
def weather_values(your_destination)
current_temp = your_destination.parsed_response['current_observation']['temp_f'].to_s
current_condition = your_destination.parsed_response['current_observation']['weather'].to_s
puts "It is " + current_temp + " and " + current_condition + "!"
end
weather_values(your_destination)
【问题讨论】:
-
你在读什么教程?它完全把你引向了错误的方向,这一切都不像 Rails,那就是 Ruby。你试过Rails for Zombies之类的吗?
-
听起来很有趣,HTTP 派对:P
标签: ruby-on-rails model-view-controller controller weather-api