【问题标题】:Ruby on Rails controller (newbie)Ruby on Rails 控制器(新手)
【发布时间】: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


【解决方案1】:

这不是铁轨。这是普通的红宝石。试试 railstutorial.org。他们有一本很棒的电子书,您可以免费在线阅读

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多