From 499a4164ce9816c4913bf3db14787ea99ef2c266 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Tue, 14 Nov 2017 10:42:10 -0500 Subject: Introduce ActiveStorage::Attached::{One,Many}#detach --- activestorage/lib/active_storage/attached/many.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activestorage/lib/active_storage/attached/many.rb') diff --git a/activestorage/lib/active_storage/attached/many.rb b/activestorage/lib/active_storage/attached/many.rb index 1e0657c33c..0b3400bccf 100644 --- a/activestorage/lib/active_storage/attached/many.rb +++ b/activestorage/lib/active_storage/attached/many.rb @@ -13,7 +13,6 @@ module ActiveStorage end # Associates one or several attachments with the current record, saving them to the database. - # Examples: # # document.images.attach(params[:images]) # Array of ActionDispatch::Http::UploadedFile objects # document.images.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload @@ -36,6 +35,11 @@ module ActiveStorage attachments.any? end + # Deletes associated attachments without purging them, leaving their respective blobs in place. + def detach + attachments.destroy_all if attached? + end + # Directly purges each associated attachment (i.e. destroys the blobs and # attachments and deletes the files on the service). def purge -- cgit v1.2.3