before_destroy
This commit is contained in:
parent
7d55141a1a
commit
fec91eeb5b
|
@ -14,7 +14,7 @@ class Ajax::AnswerController < ApplicationController
|
||||||
if answer.user == current_user
|
if answer.user == current_user
|
||||||
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
||||||
end # TODO: decide what happens with the question
|
end # TODO: decide what happens with the question
|
||||||
answer.remove
|
answer.destroy
|
||||||
|
|
||||||
@status = :okay
|
@status = :okay
|
||||||
@message = "Successfully deleted answer."
|
@message = "Successfully deleted answer."
|
||||||
|
|
|
@ -4,11 +4,14 @@ class Answer < ActiveRecord::Base
|
||||||
has_many :comments, dependent: :destroy
|
has_many :comments, dependent: :destroy
|
||||||
has_many :smiles, dependent: :destroy
|
has_many :smiles, dependent: :destroy
|
||||||
|
|
||||||
def notification_type(*_args)
|
before_destroy do
|
||||||
Notifications::QuestionAnswered
|
# mark a report as deleted if it exists
|
||||||
end
|
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.user.decrement! :answered_count
|
||||||
self.question.decrement! :answer_count
|
self.question.decrement! :answer_count
|
||||||
self.smiles.each do |smile|
|
self.smiles.each do |smile|
|
||||||
|
@ -19,6 +22,9 @@ class Answer < ActiveRecord::Base
|
||||||
Notification.denotify self.user, comment
|
Notification.denotify self.user, comment
|
||||||
end
|
end
|
||||||
Notification.denotify self.question.user, self
|
Notification.denotify self.question.user, self
|
||||||
self.destroy
|
end
|
||||||
|
|
||||||
|
def notification_type(*_args)
|
||||||
|
Notifications::QuestionAnswered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue