Rails5 + Paperclip:图像集合的Image_tag显示整个图像阵列

时间:2016-10-20 20:25:17

标签: erb ruby-on-rails-5

型号:

Place has_many Photos
Photo belongs_to Place

我想找到并显示属于某个地方的所有照片。

控制器:

@place = Place.find(params[:id])

视图:

<% if @place.photos.exists %>
    <%= @place.photos.each do |place| %>
        <%= image_tag place.photo.url(:medium)%>
    <% end %>
<% end %>

我会显示请求的照片 - 但也会显示整个照片数组:

[#<Photo id: 1, place_id: 6, title: nil, status: nil, description: nil, photo_file_name: "IMG_0436.JPG", photo_content_type: "image/jpeg", photo_file_size: 4751995, photo_updated_at: "2016-10-19 22:11:35", created_at: "2016-10-19 22:11:38", updated_at: "2016-10-19 22:11:38">, #<Photo id: 2, place_id: 6, title: nil, status: nil, description: nil, photo_file_name: "IMG_0427.JPG", photo_content_type: "image/jpeg", photo_file_size: 5683007, photo_updated_at: "2016-10-19 22:13:21", created_at: "2016-10-19 22:13:24", updated_at: "2016-10-19 22:13:24">, #<Photo id: 3, place_id: 6, title: nil, status: nil, description: nil, photo_file_name: "IMG_0428.JPG", photo_content_type: "image/jpeg", photo_file_size: 4957508, photo_updated_at: "2016-10-20 19:42:56", created_at: "2016-10-20 19:42:58", updated_at: "2016-10-20 19:42:58">]

如何仅显示图像?

1 个答案:

答案 0 :(得分:0)

您正在输出@places each

变化

<%= @place.photos.each do |place| %>

<% @place.photos.each do |place| %>