Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails_admin with devise

I have Rails_admin installed with devise and I want to restrict the /admin dashboard to only admins. For the moment my code looks like :

config.authenticate_with do
    warden.authenticate! scope: :user
  end

config.current_user_method(&:current_user)

As you can see users can get in to the dashboard so I want only the users with a boolean true in the admin column of the user table to get access to the dashboard.

How would you suggest I do this ?

like image 507
Snake Avatar asked Jan 10 '15 16:01

Snake


1 Answers

If you dont want to use cancan you can do this:

config.authorize_with do
    redirect_to main_app.root_path unless current_user.try(:admin?)
end

I use this and it works fine.

like image 66
CWitty Avatar answered Nov 15 '22 11:11

CWitty