Skip to content

Loading…

Readme documentation on using `accepts_nested_attribute_for` with Strong Parameters #118

Open
wants to merge 1 commit into from

2 participants

@emorikawa

Copied over documentation from http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html

I was banging my head against the wall for a while figuring out why the nested parameter documentation currently on the site was not working for me. I thought this would save others the headache.

I literally just copied over documentation from the StrongParameters doc on edge rails.

@drhenner

This appears to not work in all situations. I could be mistaken but it is not working for my form. :frowning:

When you print your params hash before you pass it into strong_parameters, what are the attribute fields? Do they match exactly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 6 additions and 0 deletions.
  1. +6 −0 README.md
View
6 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.
Something went wrong with that request. Please try again.