From 539868173cb0a63b9edcda5db1a053c23fcde0cc Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 18 Dec 2023 18:28:19 +0100 Subject: [PATCH] Fix `has_reacted` and `is_subscribed` not being set --- app/controllers/ajax/answer_controller.rb | 3 --- app/models/answer.rb | 2 +- app/models/user.rb | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 95651568..ba0f8f7d 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -44,9 +44,6 @@ class Ajax::AnswerController < AjaxController return if inbox - # these assigns are needed because shared/_answerbox rely on them - answer.has_reacted = false - answer.is_subscribed = false @question = 1 @response[:render] = render_to_string(partial: "answerbox", locals: { a: answer, show_question: false }) end diff --git a/app/models/answer.rb b/app/models/answer.rb index f13880f9..07a261e1 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,7 +1,7 @@ class Answer < ApplicationRecord extend Answer::TimelineMethods - attr_accessor :has_reacted, :is_subscribed + attr_writer :has_reacted, :is_subscribed belongs_to :user, counter_cache: :answered_count belongs_to :question, counter_cache: :answer_count diff --git a/app/models/user.rb b/app/models/user.rb index 1c4b0762..eb401fcd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -122,7 +122,7 @@ class User < ApplicationRecord Retrospring::Metrics::QUESTIONS_ANSWERED.increment - Answer.create!(content:, user: self, question:) + Answer.create!(content:, user: self, question:, has_reacted: false, is_subscribed: true) end # has the user answered +question+ yet?