Skip to content

Commit

Permalink
strong parameter example for hashes with integer keys.
Browse files Browse the repository at this point in the history
This replicates the situation described in
rails/strong_parameters#114
  • Loading branch information
senny committed Mar 9, 2013
1 parent 1fe5d36 commit 1d8b566
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions guides/source/action_controller_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ parameters:
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

The strong parameter API was designed with the most common use cases
Expand Down

0 comments on commit 1d8b566

Please sign in to comment.