Update models, views, and fixtures for polymorphic reactions

- Reaction: belongs_to :reactable (polymorphic) instead of :comment
- Comment: has_many :reactions with as: :reactable
- Views: use reaction.reactable instead of reaction.comment
- Fixtures: use polymorphic syntax for reactable association

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Mike Dalessio
2026-01-21 12:05:32 -05:00
parent 1570c16f67
commit ffab4cad6f
5 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ class Comment < ApplicationRecord
belongs_to :account, default: -> { card.account }
belongs_to :card, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :reactions, -> { order(:created_at) }, dependent: :delete_all
has_many :reactions, -> { order(:created_at) }, as: :reactable, dependent: :delete_all
has_rich_text :body
+3 -3
View File
@@ -1,6 +1,6 @@
class Reaction < ApplicationRecord
belongs_to :account, default: -> { comment.account }
belongs_to :comment, touch: true
belongs_to :account, default: -> { reactable.account }
belongs_to :reactable, polymorphic: true, touch: true
belongs_to :reacter, class_name: "User", default: -> { Current.user }
scope :ordered, -> { order(:created_at) }
@@ -11,6 +11,6 @@ class Reaction < ApplicationRecord
private
def register_card_activity
comment.card.touch_last_active_at
reactable.card.touch_last_active_at
end
end
@@ -15,7 +15,7 @@
class: [ "txt-small", { "txt-medium": reaction.all_emoji? } ],
data: { action: "click->reaction-delete#reveal keydown.enter->reaction-delete#reveal:prevent", reaction_delete_target: "content" } %>
<%= button_to card_comment_reaction_path(reaction.comment.card, reaction.comment, reaction),
<%= button_to card_comment_reaction_path(reaction.reactable.card, reaction.reactable, reaction),
method: :delete,
class: "reaction__delete btn btn--negative flex-item-justify-end",
data: { action: "reaction-delete#perform", reaction_delete_target: "button" } do %>
@@ -1,5 +1,5 @@
json.cache! reaction do
json.(reaction, :id, :content)
json.reacter reaction.reacter, partial: "users/user", as: :user
json.url card_comment_reaction_url(reaction.comment.card, reaction.comment, reaction)
json.url card_comment_reaction_url(reaction.reactable.card, reaction.reactable, reaction)
end
+2 -2
View File
@@ -2,12 +2,12 @@ kevin:
id: <%= ActiveRecord::FixtureSet.identify("kevin_reaction", :uuid) %>
account: 37s_uuid
content: "👍"
comment: logo_agreement_jz_uuid
reactable: logo_agreement_jz_uuid (Comment)
reacter: kevin_uuid
david:
id: <%= ActiveRecord::FixtureSet.identify("david_reaction", :uuid) %>
account: 37s_uuid
content: "👍"
comment: logo_agreement_jz_uuid
reactable: logo_agreement_jz_uuid (Comment)
reacter: david_uuid