我想显示在索引一个选择照片从多个上传的照片,在ruby on rails.我该怎么办?



Post Model

class Post < ApplicationRecord
has_many_attached :images
end

控制器

params.require(:post).permit(:title, :body, images: [])

谁来解释一下....

在Index中,您可以通过:

获取第一张图像
@posts.each do |post|
first_image = post.images.first # do something with it.
end

最新更新