I currently have a HABTM relationship between art
and art_pic_attachment
(which are images). No problem in creating objects but when I want to delete an image - I can't find any clean documentation that shows how to delete an image. I've tried the _destroy
option but nothing happens. Any clue how to fix this?
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
Model:
class Art < ApplicationRecord
has_many :art_pic_attachments, dependent: :destroy
accepts_nested_attributes_for :art_pic_attachments, allow_destroy: true
end
This wiki article discusses how to do this with Paperclip and overriding <attachment_name>_attributes=, eg.
def attachment_attributes=(attributes)
attachment.clear if has_destroy_flag?(attributes) && !attachment.dirty?
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.