From 35973b9a6e8514034f1a3350fce3f55744f11911 Mon Sep 17 00:00:00 2001 From: Mike Dillon Date: Tue, 24 May 2016 10:04:06 -0700 Subject: [PATCH] Document permitted_attributes_for_#{action} --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 8078769..5f516c9 100644 --- a/README.md +++ b/README.md @@ -597,6 +597,23 @@ class PostsController < ApplicationController 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 ### Policy Specs