1
0
Fork 0
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:
Mike Dillon 2016-05-24 10:04:06 -07:00
parent 58eda659d4
commit 35973b9a6e

View file

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