我正在使用ActiveStorage 5.2.3。我在同一模型中具有one_attachment和多个附件关系。
class Post < ApplicationRecord
has_one_attached :image
has_many_attached :photos
scope :with_eager_loading_photos, -> {eager_load photos_attachment: :blob}
attr_accessor :remove_photos
after_save do
Array(remove_photos).each { |id| photos.find_by_id(id).try(:purge) }
end
def photos_filesname
photos.map {|p| p.filename.to_s}
end
def watermarked_image
image.variant(
combine_options: {
gravity: 'center',
draw: 'image Over 0,0 200,100 "' + Rails.root.join("public/watermark.png").to_s + '"'
}
)
end
end
在我自己的应用程序级别上一切都很好。
但是,我也尝试使用Rails-Admin 1.4.2,并且一切正常,除了正确显示视频预览。
config.model 'Post' do
list do
fields :title, :content
field :image, :active_storage
field :photos, :multiple_active_storage do
delete_method :delete_photos
label 'Videos'
end
end
end
您可以看到未显示视频预览。 照片关系正在上传视频。
如何配置Rails Admin来显示视频预览?