-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update other strong param examples throughout curriculum
- Loading branch information
1 parent
a452344
commit 57c23cd
Showing
4 changed files
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ Each one of these inputs is structured slightly differently, but there are some | |
|
||
Will result in your `params` hash containing a key called `description` that you can access as normal, e.g. `params[:description]`, inside your controller. That's also why some inputs like radio buttons (where `type="radio"`) use the `name` attribute to know which radio buttons should be grouped together such that clicking one of them will unclick the others. The `name` attribute is surprisingly important! | ||
|
||
Now another thing we talked about in the controller section was nesting data. You'll often want to tuck submitted data neatly into a hash instead of keeping them all at the top level. This can be useful because, as we saw with controllers, it lets you do a one-line `#create` (once you've allowed the parameters with `#require` and `#permit`). When you access `params[:user]`, it's actually a hash containing all the user's attributes, for instance `{first_name: "foo", last_name: "bar", email: "[email protected]"}`. How do you get your forms to submit parameters like this? It's easy! | ||
Now another thing we talked about in the controller section was nesting data. You'll often want to tuck submitted data neatly into a hash instead of keeping them all at the top level. This can be useful because, as we saw with controllers, it lets you do a one-line `#create` (once you've allowed the parameters with `#expect`). When you access `params[:user]`, it's actually a hash containing all the user's attributes, for instance `{first_name: "foo", last_name: "bar", email: "[email protected]"}`. How do you get your forms to submit parameters like this? It's easy! | ||
|
||
It all comes back to the `name` attribute of your form inputs. Just use hard brackets to nest data like so: | ||
|
||
|
@@ -102,7 +102,7 @@ Those inputs will now get transformed into a nested hash under the `:user` key. | |
|
||
Specific parameters of the `params` hash are accessed like any other nested hash `params[:user][:email]`. | ||
|
||
Don't forget that you have to allow the params now in your controller using `require` and `permit` because they are a hash instead of just a flat string. See the Controller section below for a refresher on the controller side of things. | ||
Don't forget that you have to allow the params now in your controller using `#expect` because they are a hash instead of just a flat string. See the Controller section below for a refresher on the controller side of things. | ||
|
||
This is cool stuff that you'll get a chance to play with in the project. | ||
|
||
|
@@ -244,7 +244,7 @@ Just as a refresher, here's a very basic controller setup for handling `#new` ac | |
end | ||
|
||
def user_params | ||
params.require(:user).permit(:first_name, :last_name, :other_stuff) | ||
params.expect(user: [:first_name, :last_name, :other_stuff]) | ||
end | ||
... | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters