skill-assessment-app/app/controllers/admin_controller.rb

23 lines
513 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-17 17:49:09 -05:00
class AdminController < ApplicationController
2016-08-18 18:22:57 -05:00
layout 'admin'
2016-08-24 12:53:21 -05:00
before_action :authorize_admin
2016-08-18 15:35:17 -05:00
def dashboard
2016-08-18 18:22:57 -05:00
@quizzes = Quiz.includes(:questions).all
@users = User.order(:role, :name)
2016-08-18 15:35:17 -05:00
end
def current_admin
user_args = { id: session[:user], role: 'admin' }
@current_admin ||= User.find_by(user_args) if session[:user]
end
helper_method :current_admin
private
def authorize_admin
redirect_to admin_login_path unless current_admin
end
2016-08-17 17:49:09 -05:00
end