【发布时间】:2015-09-22 10:30:03
【问题描述】:
我正在使用带有 Rails 4 的 Refile。我正在关注他们的 multiple image upload 教程。每个帖子可以有多个图像。我的模型如下所示:
Post.rb:
has_many :images, dependent: :destroy
accepts_attachments_for :images, attachment: :file
图片.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>
如何使用多张图片上传来检索带有 refile 的图片?
【问题讨论】:
-
这里是 attachment_image_tag 的来源:github.com/refile/refile/blob/master/lib/refile/rails/…
-
我还忘了提到,如果我这样做
@post.images.inspect,我会得到与每个具有文件 nil 的对象的关联,并且 file_id 设置为预签名,所以我认为这部分工作正常。只是当我尝试查看错误的图像时。 -
@post是什么?它是单条记录还是记录集合?请发布@post的代码。 -
@Pavan,@post 是一条记录。我在 show.html.erb 上做了@post.inspect 并得到:
#<Post id: 2, name: "RefileTest", created_at: "2015-07-04 23:54:00", updated_at: "2015-07-04 23:54:00"
标签: ruby-on-rails ruby image file refile