docs: Update FormHelper comments to use `form_with` instead of `form_for`

This commit updates the comments in ActionView::Helpers::FormHelper, replacing instances of `form_for` with `form_with` as the recommended approach. The Rails guide has already documented the usage of `form_with` on the form_helpers page.

Ref: https://guides.rubyonrails.org/form_helpers.html

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
This commit is contained in:
takatea 2024-01-14 02:30:35 +09:00 committed by Hartley McGuire
parent 325c04c1af
commit 013667fa4e
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
1 changed files with 33 additions and 33 deletions

View File

@ -783,12 +783,12 @@ module ActionView
end
end
# Creates a scope around a specific model object like form_for, but
# Creates a scope around a specific model object like form_with, but
# doesn't create the form tags themselves. This makes fields_for suitable
# for specifying additional model objects in the same form.
#
# Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
# its method signature is slightly different. Like +form_for+, it yields
# Although the usage and purpose of +fields_for+ is similar to +form_with+'s,
# its method signature is slightly different. Like +form_with+, it yields
# a FormBuilder object associated with a particular model object to a block,
# and within the block allows methods to be called on the builder to
# generate fields associated with the model object. Fields may reflect
@ -799,7 +799,7 @@ module ActionView
# both an object name (represented by either a symbol or string) and the
# object itself can be passed to the method separately -
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# First name: <%= person_form.text_field :first_name %>
# Last name : <%= person_form.text_field :last_name %>
#
@ -880,7 +880,7 @@ module ActionView
#
# This model can now be used with a nested fields_for, like so:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :address do |address_fields| %>
# Street : <%= address_fields.text_field :street %>
@ -910,7 +910,7 @@ module ActionView
# with a value that evaluates to +true+, you will destroy the associated
# model (e.g. 1, '1', true, or 'true'):
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :address do |address_fields| %>
# ...
@ -951,7 +951,7 @@ module ActionView
# the nested fields_for call will be repeated for each instance in the
# collection:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# <% if project_fields.object.active? %>
@ -963,7 +963,7 @@ module ActionView
#
# It's also possible to specify the instance to be used:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <% @person.projects.each do |project| %>
# <% if project.active? %>
@ -977,7 +977,7 @@ module ActionView
#
# Or a collection to be used:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
# Name: <%= project_fields.text_field :name %>
@ -999,7 +999,7 @@ module ActionView
# parameter with a value that evaluates to +true+
# (e.g. 1, '1', true, or 'true'):
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# Delete: <%= project_fields.check_box :_destroy %>
@ -1011,7 +1011,7 @@ module ActionView
# object in the array. For this purpose, the <tt>index</tt> method is
# available in the FormBuilder object.
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# Project #<%= project_fields.index %>
@ -1220,7 +1220,7 @@ module ActionView
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
# shown.
#
# Using this method inside a +form_for+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
# Using this method inside a +form_with+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
#
# ==== Options
# * Creates standard HTML attributes for the tag.
@ -1629,10 +1629,10 @@ module ActionView
#
# A +FormBuilder+ object is associated with a particular model object and
# allows you to generate fields associated with the model object. The
# +FormBuilder+ object is yielded when using +form_for+ or +fields_for+.
# +FormBuilder+ object is yielded when using +form_with+ or +fields_for+.
# For example:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# Name: <%= person_form.text_field :name %>
# Admin: <%= person_form.check_box :admin %>
# <% end %>
@ -1668,7 +1668,7 @@ module ActionView
#
# The +div_radio_button+ code from above can now be used as follows:
#
# <%= form_for @person, :builder => MyFormBuilder do |f| %>
# <%= form_with model: @person, :builder => MyFormBuilder do |f| %>
# I am a child: <%= f.div_radio_button(:admin, "child") %>
# I am an adult: <%= f.div_radio_button(:admin, "adult") %>
# <% end -%>
@ -1738,7 +1738,7 @@ module ActionView
#
# return the <tt><form></tt> element's <tt>id</tt> attribute.
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%# ... %>
#
# <% content_for :sticky_footer do %>
@ -1760,7 +1760,7 @@ module ActionView
# Return the value generated by the <tt>FormBuilder</tt> for the given
# attribute name.
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%= f.label :title %>
# <%= f.text_field :title, aria: { describedby: f.field_id(:title, :error) } %>
# <%= tag.span("is blank", id: f.field_id(:title, :error) %>
@ -1781,12 +1781,12 @@ module ActionView
# Return the value generated by the <tt>FormBuilder</tt> for the given
# attribute name.
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%= f.text_field :title, name: f.field_name(:title, :subtitle) %>
# <%# => <input type="text" name="article[title][subtitle]"> %>
# <% end %>
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
# <%# => <input type="text" name="article[tag][]"> %>
# <% end %>
@ -2034,12 +2034,12 @@ module ActionView
end
end
# Creates a scope around a specific model object like form_for, but
# Creates a scope around a specific model object like form_with, but
# doesn't create the form tags themselves. This makes fields_for suitable
# for specifying additional model objects in the same form.
#
# Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
# its method signature is slightly different. Like +form_for+, it yields
# Although the usage and purpose of +fields_for+ is similar to +form_with+'s,
# its method signature is slightly different. Like +form_with+, it yields
# a FormBuilder object associated with a particular model object to a block,
# and within the block allows methods to be called on the builder to
# generate fields associated with the model object. Fields may reflect
@ -2050,7 +2050,7 @@ module ActionView
# both an object name (represented by either a symbol or string) and the
# object itself can be passed to the method separately -
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# First name: <%= person_form.text_field :first_name %>
# Last name : <%= person_form.text_field :last_name %>
#
@ -2099,7 +2099,7 @@ module ActionView
# name and value parameters are provided and the provided value has the shape of an
# option Hash. To remove the ambiguity, explicitly pass an option Hash, even if empty.
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= fields_for :permission, @person.permission, {} do |permission_fields| %>
# Admin?: <%= check_box_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
@ -2143,7 +2143,7 @@ module ActionView
#
# This model can now be used with a nested fields_for, like so:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :address do |address_fields| %>
# Street : <%= address_fields.text_field :street %>
@ -2173,7 +2173,7 @@ module ActionView
# with a value that evaluates to +true+, you will destroy the associated
# model (e.g. 1, '1', true, or 'true'):
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :address do |address_fields| %>
# ...
@ -2214,7 +2214,7 @@ module ActionView
# the nested fields_for call will be repeated for each instance in the
# collection:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# <% if project_fields.object.active? %>
@ -2226,7 +2226,7 @@ module ActionView
#
# It's also possible to specify the instance to be used:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <% @person.projects.each do |project| %>
# <% if project.active? %>
@ -2240,7 +2240,7 @@ module ActionView
#
# Or a collection to be used:
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
# Name: <%= project_fields.text_field :name %>
@ -2262,7 +2262,7 @@ module ActionView
# parameter with a value that evaluates to +true+
# (e.g. 1, '1', true, or 'true'):
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# Delete: <%= project_fields.check_box :_destroy %>
@ -2274,7 +2274,7 @@ module ActionView
# object in the array. For this purpose, the <tt>index</tt> method
# is available in the FormBuilder object.
#
# <%= form_for @person do |person_form| %>
# <%= form_with model: @person do |person_form| %>
# ...
# <%= person_form.fields_for :projects do |project_fields| %>
# Project #<%= project_fields.index %>
@ -2562,7 +2562,7 @@ module ActionView
# Add the submit button for the given form. When no value is given, it checks
# if the object is a new resource or not to create the proper label:
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%= f.submit %>
# <% end %>
#
@ -2595,7 +2595,7 @@ module ActionView
# Add the submit button for the given form. When no value is given, it checks
# if the object is a new resource or not to create the proper label:
#
# <%= form_for @article do |f| %>
# <%= form_with model: @article do |f| %>
# <%= f.button %>
# <% end %>
# In the example above, if <tt>@article</tt> is a new record, it will use "Create Article" as