You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the generator, which will set up an application policy:
rails g pundit:install
For other configurations see Pundit's readme.
In your app/policies/application_policy.rb policy you need to add rails_admin? method:
classApplicationPolicy
......
defrails_admin?(action)caseactionwhen:dashboarduser.admin?when:indexuser.admin?when:showuser.admin?when:newuser.admin?when:edituser.admin?when:destroyuser.admin?when:exportuser.admin?when:historyuser.admin?when:show_in_appuser.admin?elseraise ::Pundit::NotDefinedError,"unable to find policy #{action} for #{record}."endend# Hash of initial attributes for :new, :create and :update actions. This is optionaldefattributes_for(action)endend
Set pundit authorize method in config/initializers/rails_admin.rb initializer:
RailsAdmin.configdo |config|
## == Pundit ==config.authorize_with:pundit## == method to call for current_user ==config.current_user_method(&:current_user)
......
end
Now, in your model's policy you can specify a policy for rails_admin actions. For example: