【发布时间】:2018-11-07 21:08:18
【问题描述】:
我的问题是,当我使用 HTTParty on Rails 解析 JSON 时,如何呈现图像本身而不是图像 url。我能够在它通过时渲染 image_url 但想要那里的图像吗?例如,而不是看到: "image_url":"https://d2eyrv63e6x6lp.cloudfront.net/wp-content/uploads/2015/02/20141833/John-Smith.jpg"
我想看看它所代表的实际图像。
我正在使用 HTTParty 在 Ruby on Rails 5 上解析 JSON。
这是我目前的看法:
<table>
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Title</th>
<th>Bio</th>
<th>Vote</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @rosters.each do |roster| %>
<tr>
<td><%= roster['name'] %></td>
<td><%= roster['image_url'] %></td>
<td><%= roster['title'] %></td>
<td><%= roster['bio'] %></td>
<td><%= roster['vote'] %></td>
</tr>
<% end %>
</tbody>
</table>
当前控制器:
def index
@rosters = HTTParty.get('https://api.example', :headers =>{'Content_Type' => 'application/json'})
end
当前型号:
class Roster < ApplicationRecord
include HTTParty
end
【问题讨论】:
标签: json ruby ruby-on-rails-5