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:
parent
edf0e6ef76
commit
43ab612837
1 changed files with 16 additions and 0 deletions
16
README.md
16
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue