Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

make nested parameters of README more readable #220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,29 @@ This will mark the `:log_entry` parameters hash and any subhash of it permitted.
You can also use permit on nested parameters, like:

``` ruby
params.permit(:name, {:emails => []}, :friends => [ :name, { :family => [ :name ], :hobbies => [] }])
params.permit(:name,
{
:emails => []
},
{
:friends => [
:name,
{
:family => [ :name ],
:hobbies => []
}
]
})
```

This declaration whitelists the `name`, `emails` and `friends` attributes. It is expected that `emails` will be an array of permitted scalar values and that `friends` will be an array of resources with specific attributes : they should have a `name` attribute (any permitted scalar values allowed), a `hobbies` attribute as an array of permitted scalar values, and a `family` attribute which is restricted to having a `name` (any permitted scalar values allowed, too).
**Here is what this does**

* It whitelists the `name`, `emails` and `friends` attributes.
* It is expected that `emails` will be an array of permitted scalar values.
* It is expected that `friends` will be an array of resources with specific attributes:
* a `name` attribute (any permitted scalar values allowed)
* a `hobbies` attribute as an array of permitted scalar values
* a `family` attribute which is restricted to having a `name` (any permitted scalar values allowed, too).

Thanks to Nick Kallen for the permit idea!

Expand Down