diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index f89a1362..197849b5 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -14,7 +14,7 @@ class Ajax::AnswerController < ApplicationController if answer.user == current_user Inbox.create!(user: answer.user, question: answer.question, new: true) end # TODO: decide what happens with the question - answer.remove + answer.destroy @status = :okay @message = "Successfully deleted answer." diff --git a/app/models/answer.rb b/app/models/answer.rb index 24ce06bf..bd81d819 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -4,11 +4,14 @@ class Answer < ActiveRecord::Base has_many :comments, dependent: :destroy has_many :smiles, dependent: :destroy - def notification_type(*_args) - Notifications::QuestionAnswered - end + before_destroy do + # mark a report as deleted if it exists + rep = Report.where(target_id: self.id).first + unless rep.nil? + rep.deleted = true + rep.save + end - def remove self.user.decrement! :answered_count self.question.decrement! :answer_count self.smiles.each do |smile| @@ -19,6 +22,9 @@ class Answer < ActiveRecord::Base Notification.denotify self.user, comment end Notification.denotify self.question.user, self - self.destroy + end + + def notification_type(*_args) + Notifications::QuestionAnswered end end