1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

Readme: Namespaced policies

This commit is contained in:
Thomas Klemm 2014-07-13 12:36:14 +02:00
parent edf0e6ef76
commit 43ab612837

View file

@ -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