mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Mention second argument to authorize in README
This commit is contained in:
parent
4c234bb3a2
commit
d13f6e6568
1 changed files with 12 additions and 0 deletions
12
README.md
12
README.md
|
@ -87,6 +87,18 @@ and the given record. It then infers from the action name, that it should call
|
|||
raise "not authorized" unless PostPolicy.new(current_user, @post).create?
|
||||
```
|
||||
|
||||
You can pass a second arguent to `authorize` if the name of the permission you
|
||||
want to check doesn't match the action name. For example:
|
||||
|
||||
``` ruby
|
||||
def publish
|
||||
@post = Post.find(params[:id])
|
||||
authorize @post, :update?
|
||||
@post.publish!
|
||||
redirect_to @post
|
||||
end
|
||||
```
|
||||
|
||||
You can easily get a hold of an instance of the policy through the `policy`
|
||||
method in both the view and controller. This is especially useful for
|
||||
conditionally showing links or buttons in the view:
|
||||
|
|
Loading…
Reference in a new issue