From f9bb779b617236a88ef419819f098524ca36d4ff Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 11 Apr 2025 17:41:53 +0200 Subject: [PATCH] Use local vars so ivar dependency is only from before actions --- .../cards/comments/reactions_controller.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/cards/comments/reactions_controller.rb b/app/controllers/cards/comments/reactions_controller.rb index f843d7e42..5eee8122f 100644 --- a/app/controllers/cards/comments/reactions_controller.rb +++ b/app/controllers/cards/comments/reactions_controller.rb @@ -11,17 +11,17 @@ class Cards::Comments::ReactionsController < ApplicationController end def create - @reaction = @comment.reactions.create!(reaction_params) + reaction = @comment.reactions.create!(reaction_params) - broadcast_create - redirect_to card_comment_reactions_path(@comment.card, @comment) + broadcast_create(reaction) + redirect_to card_comment_reactions_path(@card, @comment) end def destroy - @reaction = @comment.reactions.find(params[:id]) - @reaction.destroy + reaction = @comment.reactions.find(params[:id]) + reaction.destroy - broadcast_remove + broadcast_remove(reaction) end private @@ -33,12 +33,12 @@ class Cards::Comments::ReactionsController < ApplicationController params.expect(reaction: :content) end - def broadcast_create - @reaction.broadcast_append_to @reaction.comment, :comments, + def broadcast_create(reaction) + reaction.broadcast_append_to @comment, :comments, target: "reactions_comment_#{@comment.id}", partial: "cards/comments/reactions/reaction", locals: { comment: @comment } end - def broadcast_remove - @reaction.broadcast_remove_to @reaction.comment, :comments + def broadcast_remove(reaction) + reaction.broadcast_remove_to @comment, :comments end end