我正在使用Refile with Rails 4.我正在按照他們的教程multiple image upload。每個帖子可以有多個圖像。我的模型是這樣的:重寫寶石:多個文件上傳
Post.rb:
has_many :images, dependent: :destroy
accepts_attachments_for :images, attachment: :file
Image.rb:
belongs_to :post
attachment :file
我可以通過上傳文件,罰款:
<%= f.attachment_field :images_files, multiple: true, direct: true, presigned: true %>
但是當我嘗試檢索像:
<%= attachment_image_tag(@post.images, :file, :small) %>
我得到的錯誤:
undefined method file for #<Image::ActiveRecord_Associations_CollectionProxy:0x007fbaf51e8ea0>
我怎樣才能檢索到使用多個圖像重新提交上傳圖片?
下面是attachment_image_tag來源:https://github.com/refile/refile/blob/master/lib/refile/rails/attachment_helper.rb#L39 –
我也忘了提,如果我這樣做'@ post.images.inspect',我得到每個對象的文件爲nil,file_id設置爲presigned的關聯,所以我認爲這部分工作正常。這只是當我試圖查看它的錯誤圖像。 –
'@ post'是什麼?它是***單個記錄***還是***記錄集合***?請發佈'@ post'的代碼。 – Pavan