2017-07-07 151 views
0

我一直在關注此tutorial以載波上載多個圖像。Rails使用Carrierwave上傳多個圖像

它工作正常,但它顯示的圖像下方的以下內容:

[#<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 

編輯貼子/ _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 

顯示在帖子中的圖片/ show.html.haml

[email protected] do |image| 
    = image_tag(image.url) 

任何幫助表示讚賞!

回答

0

它能正常工作,但它顯示的圖像下方的以下內容:

[#<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={}>] 

此行

[email protected] do |image| 
    = image_tag(image.url) 

應該

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

注意到其中的差別betwe en =-=用於顯示輸出。 -用於迭代對象。

+0

啊謝謝!我總是想要谷歌有什麼不同,現在我知道 – test

相關問題