2014-11-26 08:05:46 -08:00
|
|
|
class Ajax::AnswerController < ApplicationController
|
|
|
|
def destroy
|
|
|
|
params.require :answer
|
|
|
|
|
|
|
|
answer = Answer.find(params[:answer])
|
2014-11-27 02:51:05 -08:00
|
|
|
|
2014-11-28 10:23:54 -08:00
|
|
|
unless privileged? answer.user
|
2014-11-26 08:05:46 -08:00
|
|
|
@status = :nopriv
|
|
|
|
@message = "check yuor privlegs"
|
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
answer.user.decrement! :answered_count
|
2014-12-08 05:14:13 -08:00
|
|
|
answer.question.decrement! :answer_count
|
2014-11-28 05:09:12 -08:00
|
|
|
if answer.user == current_user
|
|
|
|
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
|
|
|
end # TODO: decide what happens with the question
|
2014-12-15 10:19:26 -08:00
|
|
|
Notification.denotify answer.question.user, answer
|
2014-11-26 08:05:46 -08:00
|
|
|
answer.destroy
|
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@message = "Successfully deleted answer."
|
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
end
|