How do I use the RailsAdmin.authorize_with method?

711 views Asked by At

I installed the rails admin gem, and have it working with Devise easily enough. I want to authorize the user via a boolean value, since not all users are admin. Though I'm not sure where to place the code or how it's supposed to work. i took the code from the readme, and have this currently:

RailsAdmin.authenticate_with do
  redirect_to root_path unless request.env['warden'].user.is_admin?
end

But the .user method call comes up nil, so the is_admin? fails.

Any recommendations on how I can set this up?

1

There are 1 answers

2
agmcleod On BEST ANSWER

Realized i just needed it in the application_controller

RailsAdmin.authorize_with do
  redirect_to root_path unless warden.user.is_admin?
end