How to use the RailsAdmin.authorize_with method?

I installed admin gem rails and it works with Devise quite easily. I want to authorize the user through a boolean, because not all users are administrators. Although I'm not sure where to place the code or how it should work. I took the code from readme and now this:

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

But calling the .user method appears nil, so is_admin? out of order.

Any tuning recommendations?

+3
source share
1 answer

Implemented I just needed it in application_controller

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

Source: https://habr.com/ru/post/1796346/


All Articles