Rails 使用 Carrierwave 上传多张图片

Rails Uploading multiple images with Carrierwave

我一直关注这个tutorial用载波上传多张图片。

它按预期工作,但在图像下方显示以下内容:

[#<ImageUploader:0xaeb3490 @model=#<Post id: 19, created_at: "2017-07-07 09:33:50", updated_at: "2017-07-07 09:33:50", lat: 54.635, long: -5.84582, images: ["87a8c63a9be6af171244299fc0b0a27e--stunning-art-street-art-illusions.jpg"], artist: "Vemeer", year: nil>, @mounted_as=:images, @storage=#<CarrierWave::Storage::File:0xaeb3430 @uploader=#<ImageUploader:0xaeb3490 ...>>, @file=#<CarrierWave::SanitizedFile:0xaeb3100 @file="C:/path/public/uploads/post/images/19/87a8c63a9be6af171244299fc0b0a27e--stunning-art-street-art-illusions.jpg", @original_filename=nil, @content_type=nil>, @versions={}>]

如教程中所述,为了获得多个上传,我执行了以下操作:

Rails 迁移以创建图像数组:

class AddImagesToGallery < ActiveRecord::Migration
  def change
    add_column :posts, :images, :string, array: true, default: [] 
  end
end

已编辑 posts/_form.html.haml:

= f.file_field :images, multiple: true

已编辑post_params

def post_params
    post_params.require(:post).permit(:artist, :year, :long, :lat, {images: []})
end

显示posts/show中的图像。html.haml

=@mural.images.each do |image|
    = image_tag(image.url)

感谢任何帮助!

It works as expected but it is displaying the following below the image:

[#<ImageUploader:0xaeb3490 @model=#<Post id: 19, created_at: "2017-07-07 09:33:50", updated_at: "2017-07-07 09:33:50", lat: 54.635, long: -5.84582, images: ["87a8c63a9be6af171244299fc0b0a27e--stunning-art-street-art-illusions.jpg"], artist: "Vemeer", year: nil>, @mounted_as=:images, @storage=#<CarrierWave::Storage::File:0xaeb3430 @uploader=#<ImageUploader:0xaeb3490 ...>>, @file=#<CarrierWave::SanitizedFile:0xaeb3100 @file="C:/path/public/uploads/post/images/19/87a8c63a9be6af171244299fc0b0a27e--stunning-art-street-art-illusions.jpg", @original_filename=nil, @content_type=nil>, @versions={}>]

这一行

=@mural.images.each do |image|
    = image_tag(image.url)

应该是

- @mural.images.each do |image|
    = image_tag(image.url)

注意 =- 之间的区别。 =用于显示输出。 - 用于迭代对象。