Rails5 + Paperclip:Image_tag 用于图像集合显示整个图像数组
Rails5 + Paperclip: Image_tag for a collection of images displays whole image array
型号:
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 %>
Id 显示请求的照片 - 但也显示整个照片阵列:
[#<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">]
如何只显示图片?
您正在输出 @places each
改变
<%= @place.photos.each do |place| %>
进入
<% @place.photos.each do |place| %>
型号:
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 %>
Id 显示请求的照片 - 但也显示整个照片阵列:
[#<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">]
如何只显示图片?
您正在输出 @places each
改变
<%= @place.photos.each do |place| %>
进入
<% @place.photos.each do |place| %>