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
|
|
|
|
|
2014-11-30 09:05:51 -08:00
|
|
|
begin
|
|
|
|
inbox.answer params[:answer], current_user
|
|
|
|
rescue
|
|
|
|
@status = :err
|
|
|
|
@message = "An error occurred"
|
|
|
|
@success = false
|
|
|
|
return
|
2014-11-11 09:09:28 -08:00
|
|
|
end
|
|
|
|
|
2014-11-11 07:19:20 -08:00
|
|
|
@status = :okay
|
|
|
|
@message = "Successfully answered question."
|
|
|
|
@success = true
|
|
|
|
end
|
2014-11-30 09:05:51 -08:00
|
|
|
|
|
|
|
def remove
|
|
|
|
params.require :id
|
|
|
|
|
|
|
|
inbox = Inbox.find(params[:id])
|
|
|
|
|
|
|
|
unless current_user == inbox.user
|
|
|
|
@status = :fail
|
|
|
|
@message = "question not in your inbox"
|
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
inbox.remove
|
|
|
|
rescue
|
|
|
|
@status = :err
|
|
|
|
@message = "An error occurred"
|
|
|
|
@success = false
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@message = "Successfully deleted question."
|
|
|
|
@success = true
|
|
|
|
end
|
2014-11-11 07:19:20 -08:00
|
|
|
end
|