From 43ab6128371bdbb38d6fbd51e00761b84a50e955 Mon Sep 17 00:00:00 2001 From: Thomas Klemm Date: Sun, 13 Jul 2014 12:36:14 +0200 Subject: [PATCH] Readme: Namespaced policies --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 67caae3..abb1fab 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,22 @@ conditionally showing links or buttons in the view: <%= link_to "Edit post", edit_post_path(@post) %> <% end %> ``` +## Namespaced policies + +You can namespace your policies, e.g. for using an `Admin::PostPolicy` +in your `Admin::PostsController`. Since Pundit guesses the namespace +from the controller you're calling `authorize @post` from, all you +need to do to use a namespaced policy is create it. + +```ruby +# app/policies/admin/post_policy.rb +class Admin::PostPolicy < Admin::ApplicationPolicy + # ... +end +``` + +When no namespaced policy can be found, Pundit falls back to using the +non-namespaced policy. ## Ensuring policies are used