繁体   English   中英

Ruby on Rails控制器(新手)

[英]Ruby on Rails controller (newbie)

下面是获取天气的非常简单的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)

这不是铁轨。 这是红宝石。 尝试railstutorial.org。 他们有出色的电子书,您可以免费在线阅读

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM