我在我的控制器中创建一个API调用,它返回记录列表,并将响应等同于我在视图中调用的实例变量。将实例变量传递给查看
我的控制器:
@products = Product.find(:all)
@products.each do |product|
url = URI.parse("url{product.id}")
@response1 = JSON.parse(Net::HTTP.get_response(url).body)
puts @response1
@title = @response1["ProductName"]
@url = @response1["ProductUrl"]
end
我的观点:
<div class= "title"><small><b><%= link_to truncate(@title, :length =>30), :target => '_blank' %></b></small></div>
这将显示刚接收到的响应中的一个。如何显示在我的视图中收到的所有回复。
因此,我将不得不在我看来也是API调用? – Yogzzz 2013-02-14 07:56:36
不是,但是相反 - 从控制器中删除调用并将它们放入视图中。 – Phobos98 2013-02-14 07:57:14