我目前在art
和art_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
答案 0 :(得分:0)
此wiki article讨论了如何使用Paperclip执行此操作并覆盖&lt; attachment_name&gt; _attributes =,例如。
def attachment_attributes=(attributes)
attachment.clear if has_destroy_flag?(attributes) && !attachment.dirty?
end