我正在尝试使用activestorage删除从activeadmin上传的图像。我成功地在资源的展示视图和编辑视图中显示了所有图片,但如果我想要删除每个图片,我似乎找不到方法。我的模型代码如下:
class Category < ApplicationRecord
has_many_attached :images
end
活动管理的资源文件:
ActiveAdmin.register Category do
permit_params :category_name, :description, :photo_cover, images: []
index do
selectable_column
id_column
column :category_name
column :created_at
actions
end
show do |t|
if t.photo_cover.attached? && t.images.attached?
attributes_table do
row :category_name
row :description
row "images" do |m|
m.images.each do |img|
span do
image_tag(img)
end
end
end
end
else
attributes_table do
row :category_name
row :description
end
end
end
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Basic Info" do
f.input :category_name
f.input :description
end
f.inputs do
f.input :images, as: :file, input_html: { multiple: true }
end
if f.object.images.attached?
f.object.images.each do |img|
span do
image_tag(img)
end
end
end
f.actions
end
end
Thank you in advance!!
a "Delete", href: delete...
而不是a "Delete", src: delete
,因为它是一个 a 标签。 - Hector Acosta