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