Luc
Luc

Reputation: 17072

Hide ActiveAdmin menu but does not disable it

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

Answers (1)

maximus ツ
maximus ツ

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

Related Questions