before_destroy
This commit is contained in:
parent
7d55141a1a
commit
fec91eeb5b
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue