mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
strong parameter example for hashes with integer keys.
This replicates the situation described in https://github.com/rails/strong_parameters/issues/114
This commit is contained in:
parent
1fe5d36e11
commit
1d8b566478
1 changed files with 14 additions and 0 deletions
|
@ -290,6 +290,20 @@ parameters:
|
||||||
params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy])
|
params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy])
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Hasesh with integer keys are treated differently and you can declare
|
||||||
|
the attributes as if they were direct children. You get this kind of
|
||||||
|
parameters when you use `accepts_nested_attributes_for` in combination
|
||||||
|
with a `has_many` association:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
# To whitelist the following data:
|
||||||
|
# {"book" => {"title" => "Some Book",
|
||||||
|
# "chapters_attributes" => { "1" => {"title" => "First Chapter"},
|
||||||
|
# "2" => {"title" => "Second Chapter"}}}}
|
||||||
|
|
||||||
|
params.require(:book).permit(:title, chapters_attributes: [:title])
|
||||||
|
```
|
||||||
|
|
||||||
#### Outside the Scope of Strong Parameters
|
#### Outside the Scope of Strong Parameters
|
||||||
|
|
||||||
The strong parameter API was designed with the most common use cases
|
The strong parameter API was designed with the most common use cases
|
||||||
|
|
Loading…
Reference in a new issue