From 57d0c995cf7e623e77fd686e628d9ebbe34f13d0 Mon Sep 17 00:00:00 2001 From: Pablo Crivella Date: Fri, 9 Mar 2018 18:23:15 +0100 Subject: [PATCH] Update README with examples for overriding pundit_params_for method --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 9b050ea..d6a8b96 100644 --- a/README.md +++ b/README.md @@ -669,6 +669,28 @@ 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. +If you need to fetch parameters based on namespaces different from the suggested one, override the below method and return an instance of `ActionController::Parameters`. + +```ruby +def pundit_params_for(record) + params.require(PolicyFinder.new(record).param_key) +end +``` + +For example: + +```ruby +# If you don't want to use require +def pundit_params_for(record) + params.fetch(PolicyFinder.new(record).param_key, {}) +end + +# If you are using something like the jsonapi spec +def pundit_params_for(_record) + params.fetch(:data, {}).fetch(:attributes, {}) +end +``` + ## RSpec ### Policy Specs