skill-assessment-app/app/controllers/admin_controller.rb
2016-09-19 16:40:56 -05:00

31 lines
739 B
Ruby

# frozen_string_literal: true
class AdminController < ApplicationController
include Pundit
layout 'admin'
before_action :authorize_user
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
def dashboard
authorize :admin, :dashboard?
@quizzes = Quiz.includes(:questions).all
@users = User.order(:role, :name)
end
def current_user
@current_user ||= User.find_by(id: session[:user]) if session[:user]
end
helper_method :current_user
private
def authorize_user
redirect_to admin_login_path unless current_user
end
def user_not_authorized
flash[:error] = "You are not authorized to perform this action."
redirect_to(request.referer || root_path)
end
end