diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 47950c51..f89a1362 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -11,13 +11,10 @@ class Ajax::AnswerController < ApplicationController return end - answer.user.decrement! :answered_count - answer.question.decrement! :answer_count if answer.user == current_user Inbox.create!(user: answer.user, question: answer.question, new: true) end # TODO: decide what happens with the question - Notification.denotify answer.question.user, answer - answer.destroy + answer.remove @status = :okay @message = "Successfully deleted answer." diff --git a/app/models/answer.rb b/app/models/answer.rb index f5bf0af9..24ce06bf 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -7,4 +7,18 @@ class Answer < ActiveRecord::Base def notification_type(*_args) Notifications::QuestionAnswered end + + def remove + self.user.decrement! :answered_count + self.question.decrement! :answer_count + self.smiles.each do |smile| + Notification.denotify self.user, smile + end + self.comments.each do |comment| + comment.user.decrement! :commented_count + Notification.denotify self.user, comment + end + Notification.denotify self.question.user, self + self.destroy + end end