Prior to this commit, there were two sections in the Form Helpers guide
with the same heading "The `fields_for` Helper".
This commit differentiates those two headings, and makes some minor
improvements to both sections for clarity.
This:
```ruby
resource :geocoder
```
and this:
```ruby
resource :geocoder
resolve('Geocoder') { [:geocoder] }
```
create exactly the same routes. Thus, it's better to show the simpler example rather than imply that both method calls are needed.
`resolve` is used for [polymorphic routes](https://guides.rubyonrails.org/routing.html#using-resolve) but isn't necessary in this example.
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.
All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
This shifts the primary focus from the bare `select_*` helpers to the
equivalent `FormBuilder#*_select` helpers. It also links all covered
helpers to their API documentation.
The previous statement was not strictly true all of the time.
For example, an input named `person[phone_number[]]` does
not get automatically accumulated. Updated this to a statement
that is always true (even if it may not fully describe all possible
cases, such as perhaps nested forms).
Follow-up to #39344.
This adds back coverage of `collection_select`, adds new coverage of
`collection_radio_buttons`, revises existing coverage of
`collection_check_boxes`, and unifies these sections.
The Form Helpers guide should encourage users to use `form_with` and
associated builder methods. The lower-level `*_tag` methods are covered
by the API docs.
These changes also fix some discrepancies between code examples and
their descriptions.
I caught two references that seemed inconsistent:
1. In section 2.2 Binding a Form to an Object, the code snippet variable was called `form`, but in the bullet points below, it was referenced as `f`.
2. In section 6 Uploading Files, the references to the params hash returned by two different forms was incorrect.
Motivation:
- I frequently look for this in the docs then struggle to rememeber
the name of the function I need to find in the api docs. Also I think
other people may benefit from it being easier to find.
Changes:
- Added a section about Collection Checkboxes to the docs.
Co-Authored-By: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
Convert examples to use `form_with` instead of `form_for` or `form_tag`,
which have been soft-deprecated. Also rename form variable in examples
from `f` to `form`, as exemplified by 8ff7ca5d11.
The description claimed that `.new_record?` was used in `form_for` to derive the action and button text.
But in the code `.persisted?` is used for that purpose.
[ci skip]
This commit is the next work after #33523.
Also, this commit removes mention about hidden `utf8` input. Since
form helpers don't generate this input by default since #32125.
Note that I also had created PR #31972 with improvements to
"Action View Form Helpers" guide, but I'll rebase it after merging the
current PR.
* Include form_with in form_helpers rails guide
* Include form_tag and form_for footnote
* Id and class attributes are not wrapped anymore
* Include note that all form_with forms are remote:true by default
* Underline most common use case of form_with is with arguments
* Form_with no longer accepts multiple hashes in form helper calls
* Review final sections
* Revert extra documentation
* Remove unnecessary link
Paperclip has officially been deprecated, so we shouldn't mention it
anymore.
CarrierWave could still be referenced, as there are use cases where it
currently makes more sense, but for simplicity, I thought removing the
mention of third party libraries made sense. If we want to talk about
them, listing "alternatives" within the Active Storage guide could make
more sense.
[ci skip] A regular expression was used to find a lot of missing Oxford
commas and add them. The regular expression was as follows.
", ([a-zA-Z0-9.\`:'\"]+ ){1,6}(or|and) "
* It looks that example codes are not based on actual output. So I've fixed it.
* Specifically:
* There are no lines about utf-8 and authenticity_token.
* The submit button doesn't have data-disabled-with attribute.
* Each attribute order of html element is different from actual ones.
If the example for complex forms is implemented, ActiveRecord will prevent saving unless `inverse_of: :person` is added to the `has_many :addresses` association.