Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails无意中在视图中显示JSON_Ruby On Rails_Json - Fatal编程技术网

Ruby on rails Rails无意中在视图中显示JSON

Ruby on rails Rails无意中在视图中显示JSON,ruby-on-rails,json,Ruby On Rails,Json,我正在使用Rails 4,在我的一个视图中有一个奇怪的问题。在我的控制器中,我使用gem从OpenWeatherMap.org获取天气提要。数据以JSON的形式返回,我在JSON中循环并提取未来5天的预测信息。奇怪的是,在我的循环之后,会显示JSON数据 我不熟悉Rails和JSON,这对我来说没有任何意义。我有第二个页面,有更多的信息,同样的事情也发生了。这就是我的控制器的外观: def index options = { units: "Imperial", APPID: '6

我正在使用Rails 4,在我的一个视图中有一个奇怪的问题。在我的控制器中,我使用gem从OpenWeatherMap.org获取天气提要。数据以JSON的形式返回,我在JSON中循环并提取未来5天的预测信息。奇怪的是,在我的循环之后,会显示JSON数据

我不熟悉Rails和JSON,这对我来说没有任何意义。我有第二个页面,有更多的信息,同样的事情也发生了。这就是我的控制器的外观:

  def index
    options = { units: "Imperial", APPID: '6eff99d4b460d3a1acddcf1a727a7a45' }
    @currentweather = OpenWeather::Current.city("Greenville, SC", options)
    @forcastweather = OpenWeather::ForecastDaily.city("Greenville, SC", options)
  end
    <%= @forcastweather['list'].each do | day | %>
    <div class ="row">
      <div class="col-xs-5">
        <strong><%= Time.at(DateTime.strptime(day['dt'].to_s,'%s')).in_time_zone("Eastern Time (US & Canada)").strftime("%A") %></strong>
      </div>
      <div class="col-xs-3">
        <%= day['temp']['min'] %>
      </div>
      <div class="col-xs-3">
        <%= day['temp']['max'] %>
      </div>
      <div class="col-xs-2">
        <img src="http://openweathermap.org/img/w/<%= day['weather'][0]['icon'] %>.png" alt="<%= day['weather'][0]['main'].humanize %>">
      </div>
    </div>
  <% end %>
这就是我的观点:

  def index
    options = { units: "Imperial", APPID: '6eff99d4b460d3a1acddcf1a727a7a45' }
    @currentweather = OpenWeather::Current.city("Greenville, SC", options)
    @forcastweather = OpenWeather::ForecastDaily.city("Greenville, SC", options)
  end
    <%= @forcastweather['list'].each do | day | %>
    <div class ="row">
      <div class="col-xs-5">
        <strong><%= Time.at(DateTime.strptime(day['dt'].to_s,'%s')).in_time_zone("Eastern Time (US & Canada)").strftime("%A") %></strong>
      </div>
      <div class="col-xs-3">
        <%= day['temp']['min'] %>
      </div>
      <div class="col-xs-3">
        <%= day['temp']['max'] %>
      </div>
      <div class="col-xs-2">
        <img src="http://openweathermap.org/img/w/<%= day['weather'][0]['icon'] %>.png" alt="<%= day['weather'][0]['main'].humanize %>">
      </div>
    </div>
  <% end %>


.png“alt=”“>
为什么JSON显示在我的视图中?我如何修复它?


<%= @forcastweather['list'].each do | day | %>
把钥匙拿出来

<% @forcastweather['list'].each do | day | %>


使用
很高兴我能帮助@mack,请接受答案以结束问题!