authorization rails_admin with pundit

偶尔善良 提交于 2021-02-07 08:27:46

问题


I use pundit gem to authorization.

In my file config/initializers/rails_admin.rb

RailsAdmin.config do |config|
  config.authorize_with :pundit

  config.current_user_method(&:current_user)
  ......
end

I follow the instructions in https://github.com/sudosu/rails_admin_pundit But in when run code, error :

protected method `policy' called for #<Rails_Admin::MainController

I use rails_admin 0.8.1

Please guide me use pundit in rails_admin ( tutorial, examle, ...)


回答1:


You can try to use this gem or just make default authorization.

Add this to config/initializers/rails_admin.rb file:

  config.authorize_with do
    redirect_to main_app.root_path, error: 'You are not authorized to perform this action.' unless current_user.admin?
  end


来源:https://stackoverflow.com/questions/36288801/authorization-rails-admin-with-pundit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!