I have a User model with a boolean switch to designate admin t/f. My current application controller:
class ApplicationController < ActionController::Base
protect_from_forgery
def after_sign_in_path_for(user)
if current_user.admin?
admin_index_path
else
dashboard_index_path
end
end
end
My current admin controller:
class AdminController < ApplicationController
def index
if current_user.admin?
admin_index_path
else
home_index_path
end
end
end
The goal is of course to only allow access to the admin index page to admin users. The redirect works fine when I sign in as admin, but I'm getting a NoMethodError in AdminController#index error when I navigate to admin_index_path as an non-admin user (undefined method `admin?' for nil:NilClass). Help on this issue? I feel like there is probably a CanCan solution that would be more elegant and secure, but I haven't found a good explanation of how to accomplish that. Thoughts? Thanks in advance!