2014-11-11 07:19:20 -08:00
|
|
|
class Ajax::InboxController < ApplicationController
|
|
|
|
def destroy
|
|
|
|
params.require :id
|
|
|
|
params.require :answer
|
|
|
|
|
2014-11-11 09:02:59 -08:00
|
|
|
inbox = Inbox.find(params[:id])
|
2014-11-11 07:19:20 -08:00
|
|
|
|
2014-11-11 09:02:59 -08:00
|
|
|
unless current_user == inbox.user
|
2014-11-11 07:19:20 -08:00
|
|
|
@status = :fail
|
|
|
|
@message = "question not in your inbox"
|
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
answer = Answer.create(content: params[:answer],
|
|
|
|
user: current_user,
|
|
|
|
question: inbox.question)
|
|
|
|
|
2014-11-11 09:09:28 -08:00
|
|
|
unless current_user.nil?
|
|
|
|
current_user.increment! :answered_count
|
|
|
|
end
|
|
|
|
|
2014-11-11 07:19:20 -08:00
|
|
|
Inbox.destroy inbox.id
|
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@message = "Successfully answered question."
|
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
end
|