Reputation: 17072
In my AA app, I use the following instruction to hide the menu I do not want non admin users to see:
menu :if => proc{ current_user.is_admin? }
but this does not prevent those users to enter /admin/users in the url and to access the users menu content. What is the best way to prevent non admin user to access hidden menu ?
Upvotes: 1
Views: 1541
Reputation: 8065
You can do this with cancan or can write your own filter like this,
controller do
before_filter :check_admin
def check_admin
unless current_user.is_admin?
redirect_to "/", :error => "Access denied"
end
end
end
for cancan gem, you need to define ability file and then you can use
controller.authorize_resource
method provided by activeadmin.
Upvotes: 2