From 6fb97c9ecc3c5e916655b68d8b5c1042cc96e207 Mon Sep 17 00:00:00 2001 From: nilsding Date: Thu, 27 Nov 2014 11:51:05 +0100 Subject: [PATCH] moved privileged? method from answer_controller to application_controller --- app/controllers/ajax/answer_controller.rb | 13 ++----------- app/controllers/application_controller.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 245fa12f..ab45255e 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -8,6 +8,8 @@ class Ajax::AnswerController < ApplicationController answer = Answer.find(params[:answer]) + puts ">>>>>>>>>>>>", privileged?.inspect + unless answer.user == current_user || privileged? @status = :nopriv @message = "check yuor privlegs" @@ -23,15 +25,4 @@ class Ajax::AnswerController < ApplicationController @message = "Successfully deleted answer." @success = true end - - private - - # TODO: - def privileged? - if current_user && current_user.admin? - true - else - false - end - end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fbe8b9d1..581c63bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,15 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_filter :configure_permitted_parameters, if: :devise_controller? - + + def privileged? + if current_user && current_user.admin? + true + else + false + end + end + protected def configure_permitted_parameters