I have an admin controller and I want that only users that are defined as admin would have access to that controller.
my ability class:
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end
my admin controller:
class AdminController < ApplicationController
load_and_authorize_resource
def index
end
def users_list
end
end
when i try to access /admin/users_list
(either with an admin user or without) i get the following error: uninitialized constant Admin
What am I doing wrong? Is that the right way to restrict access to a controller?
build
inreports_controller.rb
with specific report name. I'm trying to define abilities like this:can :read, :reports, name: ['Orders', 'Payments']
and then check permissions:if can? :read, :reports, name: 'Orders'
but errorundefined method 'name' for :reports:Symbol
is happened. Do you have any ideas? – Creamer