moved some code

This commit is contained in:
nilsding 2014-12-28 21:20:07 +01:00
parent 6d81b4a24b
commit b6c0b1864a
2 changed files with 15 additions and 4 deletions

View File

@ -11,13 +11,10 @@ class Ajax::AnswerController < ApplicationController
return return
end end
answer.user.decrement! :answered_count
answer.question.decrement! :answer_count
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
Notification.denotify answer.question.user, answer answer.remove
answer.destroy
@status = :okay @status = :okay
@message = "Successfully deleted answer." @message = "Successfully deleted answer."

View File

@ -7,4 +7,18 @@ class Answer < ActiveRecord::Base
def notification_type(*_args) def notification_type(*_args)
Notifications::QuestionAnswered Notifications::QuestionAnswered
end 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 end