mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Document permitted_attributes_for_#{action}
This commit is contained in:
parent
58eda659d4
commit
35973b9a6e
1 changed files with 17 additions and 0 deletions
17
README.md
17
README.md
|
@ -597,6 +597,23 @@ class PostsController < ApplicationController
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to permit different attributes based on the current action, you can define a `permitted_attributes_for_#{action}` method on your policy:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
# app/policies/post_policy.rb
|
||||||
|
class PostPolicy < ApplicationPolicy
|
||||||
|
def permitted_attributes_for_create
|
||||||
|
[:title, :body]
|
||||||
|
end
|
||||||
|
|
||||||
|
def permitted_attributes_for_edit
|
||||||
|
[:body]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you have defined an action-specific method on your policy for the current action, the `permitted_attributes` helper will call it instead of calling `permitted_attributes` on your controller.
|
||||||
|
|
||||||
## RSpec
|
## RSpec
|
||||||
|
|
||||||
### Policy Specs
|
### Policy Specs
|
||||||
|
|
Loading…
Reference in a new issue