如何在ActiveAdmin表单中删除图像?

时间:2018-03-11 03:02:43

标签: ruby-on-rails activeadmin

我目前在artart_pic_attachment之间有HABTM关系(图像)。创建对象没有问题但是当我想删除图像时 - 我找不到任何显示如何删除图像的干净文档。我尝试了_destroy选项,但没有任何反应。有任何线索如何解决这个问题?

ActiveAdmin.register Art do

permit_params :art_pic_attachments_attributes: [:id, :picture, :_destroy]

 form(html: { multipart: true }) do |f|
    f.inputs do

        f.has_many :art_pic_attachments, allow_destroy: true, heading: 'Images' do |ff|
            ff.file_field :picture, required: true, heading: "Pictures"
        end

    end
        f.actions
 end 

型号:

class Art < ApplicationRecord
        has_many :art_pic_attachments, dependent: :destroy
        accepts_nested_attributes_for :art_pic_attachments, allow_destroy: true  
    end

1 个答案:

答案 0 :(得分:0)

wiki article讨论了如何使用Paperclip执行此操作并覆盖&lt; attachment_name&gt; _attributes =,例如。

def attachment_attributes=(attributes)
  attachment.clear if has_destroy_flag?(attributes) && !attachment.dirty?
end