before_destroy

This commit is contained in:
nilsding 2014-12-28 21:34:42 +01:00
parent 7d55141a1a
commit fec91eeb5b
2 changed files with 12 additions and 6 deletions

View File

@ -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."

View File

@ -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