From 92bbcbb7ceb4aa206b3d98f33cac18ce03646b61 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 5 Apr 2022 15:48:14 +1000 Subject: [PATCH] Process correct attachment when model has several Luckily Paperclip has designated callbacks for processing each attachment separately. We can just hook into that. --- app/models/concerns/has_migrating_file.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/has_migrating_file.rb b/app/models/concerns/has_migrating_file.rb index d82528f38c..83d736ab93 100644 --- a/app/models/concerns/has_migrating_file.rb +++ b/app/models/concerns/has_migrating_file.rb @@ -22,10 +22,10 @@ module HasMigratingFile # We store files with Paperclip *and* Active Storage while we migrate # old Paperclip files to Active Storage. This enables availability # during the migration. - after_post_process do - if public_send(name).errors.blank? - file = File.open(processed_local_file_path) - attach_file(name, file) + public_send("after_#{name}_post_process") do + path = processed_local_file_path(name) + if public_send(name).errors.blank? && path.present? + attach_file(name, File.open(path)) end end end