Activeadmin - activestorage 删除编辑多张照片

Activeadmin - activestorage delete edit multiple photos

我正在尝试找到一种方法来删除使用 activestorage 从 activeadmin 上传的图像。我设法在显示视图和资源编辑中显示了所有图像,但我似乎无法找到删除每张图像的方法(如果我愿意的话)。我的模型代码:

  class Category < ApplicationRecord
    has_many_attached :images
  end

以及activeadmin资源文件:

   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

提前致谢!!

按照说明在 ActiveAdmin 模型中创建自定义路由 here

member_action :delete_category_image, method: :delete do
  @pic = ActiveStorage::Attachment.find(params[:id])
  @pic.purge_later
  redirect_back(fallback_location: edit_admin_category_path)   
end

form do,

f.object.images.each do |img|
  li class: "some_class" do
    figure do
      img src: rails_representation_path(img.variant(resize_to_fit: [200, 200])), alt: "Photo"
      figcaption img.blog.filename
    end

    a "Delete", src: delete_category_image_admin_category_path(img.id), "data-method": :delete, "data-confirm": "Are you sure?"
  end
end