theseus/app/controllers/admin/application_controller.rb
2025-05-31 23:25:41 -04:00

21 lines
694 B
Ruby

# All Administrate controllers inherit from this
# `Administrate::ApplicationController`, making it the ideal place to put
# authentication logic or other before_actions.
#
# If you want to add pagination or other controller-level concerns,
# you're free to overwrite the RESTful controller actions.
module Admin
class ApplicationController < Administrate::ApplicationController
before_action :authenticate_admin
def authenticate_admin
redirect_to root_path, alert: "you can't do that!" unless current_user&.admin?
end
helper_method :current_user
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
end
end