From b5673604758da33a18f013f0b9b66bae4aeff4eb Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Mon, 11 Mar 2013 17:17:23 -0400 Subject: [PATCH] Documentation for using `accepts_nested_attributes_for` with Strong Parameters Copied over documentation from http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 574e10a..7e3e425 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ This declaration whitelists the `name`, `emails` and `friends` attributes. It is Thanks to Nick Kallen for the permit idea! +In order to use `accepts_nested_attribute_for` with Strong Parameters, you will need to specify which nested attributes should be whitelisted. It's mandatory to specify the nested attributes that should be whitelisted. If you use `permit` with just the key that points to the nested attributes hash, it will return an empty hash. + +``` ruby +params.require(:person).permit(:name, :age, pets_attributes: [ :name, :category ]) +``` + ## Handling of Unpermitted Keys By default parameter keys that are not explicitly permitted will be logged in the development and test environment. In other environments these parameters will simply be filtered out and ignored.