Messageables already have access to the card

This commit is contained in:
David Heinemeier Hansson
2025-04-12 11:00:15 +02:00
parent 24b02c42fd
commit b698eefa06
3 changed files with 8 additions and 7 deletions
+4 -3
View File
@@ -10,9 +10,10 @@ class Comment < ApplicationRecord
before_destroy :cleanup_events
def created_via(message)
message.card.watch_by creator
message.card.track_event :commented, comment_id: id
# Called when a new comment is captured as a message during creation
def created_via_message
card.watch_by creator
card.track_event :commented, comment_id: id
end
def to_partial_path
+2 -2
View File
@@ -8,11 +8,11 @@ module Messageable
has_one :card, through: :message
end
def created_via(message)
def created_via_message
# Overwrite in Messageable class
end
def destroyed_via(message)
def destroyed_via_message
# Overwrite in Messageable class
end
end
+2 -2
View File
@@ -5,6 +5,6 @@ class Message < ApplicationRecord
scope :chronologically, -> { order created_at: :asc, id: :desc }
after_create -> { messageable.created_via(self) }
after_destroy -> { messageable.destroyed_via(self) }
after_create -> { messageable.created_via_message }
after_destroy -> { messageable.destroyed_via_message }
end