Skip to content

Commit

Permalink
Update form_helpers.md section 1
Browse files Browse the repository at this point in the history
The edits in section 1.2.1 of this guide are being proposed as the value argument passed to `check_box` is not in the second position, it is the third argument as shown [here](https://api.rubyonrails.org/v7.0.3/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box) and in turn the language around the argument list for `radio_button` in section 1.2.2 needed to be altered as well.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
  • Loading branch information
cjilbert504 committed May 26, 2022
1 parent ad36ab6 commit 4908a5a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions guides/source/form_helpers.md
Expand Up @@ -86,7 +86,7 @@ value entered by the user for that field. For example, if the form contains
`<%= form.text_field :query %>`, then you would be able to get the value of this
field in the controller with `params[:query]`.

When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in `params`. You can read more about them in chapter [Understanding Parameter Naming Conventions](#understanding-parameter-naming-conventions) of this guide. For details on the precise usage of these helpers, please refer to the [API documentation](https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html).
When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in `params`. You can read more about them in the [Understanding Parameter Naming Conventions](#understanding-parameter-naming-conventions) section of this guide. For details on the precise usage of these helpers, please refer to the [API documentation](https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html).

#### Checkboxes

Expand All @@ -108,7 +108,7 @@ This generates the following:
<label for="pet_cat">I own a cat</label>
```

The first parameter to [`check_box`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box) is the name of the input. The second parameter is the value of the input. This value will be included in the form data (and be present in `params`) when the checkbox is checked.
The first parameter to [`check_box`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box) is the name of the input. The checkbox's values (the values that will appear in `params`) can optionally be specified using the third and fourth parameters. See the API documentation for details.

#### Radio Buttons

Expand All @@ -130,7 +130,7 @@ Output:
<label for="age_adult">I am over 21</label>
```

As with `check_box`, the second parameter to [`radio_button`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-radio_button) is the value of the input. Because these two radio buttons share the same name (`age`), the user will only be able to select one of them, and `params[:age]` will contain either `"child"` or `"adult"`.
The second parameter to [`radio_button`](https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-radio_button) is the value of the input. Because these two radio buttons share the same name (`age`), the user will only be able to select one of them, and `params[:age]` will contain either `"child"` or `"adult"`.

NOTE: Always use labels for checkbox and radio buttons. They associate text with a specific option and,
by expanding the clickable region,
Expand Down

0 comments on commit 4908a5a

Please sign in to comment.