added (ajax) answer controller
This commit is contained in:
parent
96dbb77f7c
commit
8dff4462cf
|
@ -0,0 +1,37 @@
|
||||||
|
class Ajax::AnswerController < ApplicationController
|
||||||
|
def destroy
|
||||||
|
params.require :answer
|
||||||
|
|
||||||
|
unless current_user.nil?
|
||||||
|
current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true'
|
||||||
|
end
|
||||||
|
|
||||||
|
answer = Answer.find(params[:answer])
|
||||||
|
|
||||||
|
unless answer.user == current_user || privileged?
|
||||||
|
@status = :nopriv
|
||||||
|
@message = "check yuor privlegs"
|
||||||
|
@success = false
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
answer.user.decrement! :answered_count
|
||||||
|
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
||||||
|
answer.destroy
|
||||||
|
|
||||||
|
@status = :okay
|
||||||
|
@message = "Successfully deleted answer."
|
||||||
|
@success = true
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
def privileged?
|
||||||
|
if current_user && current_user.admin?
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1 @@
|
||||||
|
json.partial! 'ajax/shared/status'
|
|
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
||||||
namespace :ajax do
|
namespace :ajax do
|
||||||
match '/ask', to: 'question#create', via: :post, as: :ask
|
match '/ask', to: 'question#create', via: :post, as: :ask
|
||||||
match '/answer', to: 'inbox#destroy', via: :post, as: :answer
|
match '/answer', to: 'inbox#destroy', via: :post, as: :answer
|
||||||
|
match '/destroy_answer', to: 'answer#destroy', via: :post, as: :destroy_answer
|
||||||
end
|
end
|
||||||
|
|
||||||
match '/inbox', to: 'inbox#show', via: 'get'
|
match '/inbox', to: 'inbox#show', via: 'get'
|
||||||
|
|
Loading…
Reference in New Issue