【发布时间】:2017-03-09 04:35:30
【问题描述】:
Rails API 的新手。我想在我的视图中显示更新图片。我从中提取的 JSON 数据可以在 here
找到我的模特
def self.get_api_info
helio_api = "http://www.lmsal.com/hek/her?cosec=2&cmd=search&type=column&event_type=fl,bu&event_starttime=2017-03-01T00:00:00&event_endtime=2017-03-08T00:00:00&event_coordsys=helioprojective&x1=-1200&x2=1200&y1=-1200&y2=1200"
request_to_helio_api = Net::HTTP.get(URI(helio_api))
JSON.parse request_to_helio_api
end
我的控制器
def index
@helio_info = HelioApi.get_api_info
end
我的观点
<img src="<%= @helio_info["gs_thumburl"] %>" />
【问题讨论】:
-
试试
<img src="<%= @helio_info["result"]["gs_thumburl"] %>" /> -
我认为错误在于我如何处理 API 的模型。但是,当我尝试这样做时,我得到了“没有将字符串隐式转换为整数”
标签: ruby-on-rails json hash