aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-03-05 02:04:31 -0800
committerXavier Noria <fxn@hashref.com>2013-03-05 02:04:31 -0800
commit3f490caeef38d2e88b50d49692a204d2e9424c67 (patch)
tree4e7ffb09c9b243c81d7a9941b5ad8b3aa421272b
parent40936da37222f3a669505b8e428062c4118ca30e (diff)
parent0e7abf21dd38ab6fb402843afb8ac42ec550d901 (diff)
downloadrails-3f490caeef38d2e88b50d49692a204d2e9424c67.tar.gz
rails-3f490caeef38d2e88b50d49692a204d2e9424c67.tar.bz2
rails-3f490caeef38d2e88b50d49692a204d2e9424c67.zip
Merge pull request #9556 from senny/strong_params_examples
strong parameters example for default values using `fetch`.
-rw-r--r--guides/source/action_controller_overview.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md
index e65f7e5b18..61eb2ef089 100644
--- a/guides/source/action_controller_overview.md
+++ b/guides/source/action_controller_overview.md
@@ -269,6 +269,27 @@ 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).
+#### More Examples
+
+You want to also use the permitted attributes in the `new`
+action. This raises the problem that you can't use `require` on the
+root-key because normally it does not exist when calling `new`:
+
+```ruby
+# using `fetch` you can supply a default and use
+# the Strong Parameters API from there.
+params.fetch(blog:, {}).permit(:title, :author)
+```
+
+`accepts_nested_attributes_for` allows you update and destroy the
+associated records. This is based on the `id` and `_destroy`
+parameters:
+
+```ruby
+# permit :id and :_destroy
+params.require(:author).permit(:name, books_attributes: [:title, :id, :_destroy])
+```
+
#### Outside the Scope of Strong Parameters
The strong parameter API was designed with the most common use cases