From b20ddde5f6e0a076cb263c4eb2777fe6949767b5 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Wed, 29 Oct 2025 10:31:19 -0500 Subject: [PATCH] Capture `old_collection` before it changes Fixes: https://box-car.com/5986089/cards/2577 in which the old and new collection name would always be the destination (current) collection --- app/models/card.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/card.rb b/app/models/card.rb index 7893db85a..64cf71928 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -59,20 +59,19 @@ class Card < ApplicationRecord end def handle_collection_change + old_collection = Collection.find_by(id: collection_id_before_last_save) + transaction do update! column: nil - track_collection_change_event + track_collection_change_event(old_collection.name) grant_access_to_assignees unless collection.all_access? end remove_inaccessible_notifications_later end - def track_collection_change_event - old_collection = Collection.find_by(id: collection_id_before_last_save) - if old_collection.present? - track_event "collection_changed", particulars: { old_collection: old_collection.name, new_collection: collection.name } - end + def track_collection_change_event(old_collection_name) + track_event "collection_changed", particulars: { old_collection: old_collection_name, new_collection: collection.name } end def grant_access_to_assignees