Add docs for `data-turbo-method` and `data-turbo-confirm` for `link_to`

Rails 7 ships with Turbo enabled by default. Instead of using
`data-method` and `data-confirm`, Turbo now uses `data-turbo-method` and
`data-turbo-confirm` to perform a link visit with the specified HTTP
method and show confirmation dialog respective.

The deprecated legacy options are documented but the new options are
not.

This commit documents the `data-turbo-method` and `data-turbo-confirm`
for the `link_to` method.

The `button_to` documentation has also been updated to reference the
new `link_to` options.
This commit is contained in:
julianfssen 2023-02-26 12:29:48 +08:00
parent 6db58ed7b6
commit 6a798d079a
1 changed files with 26 additions and 3 deletions

View File

@ -173,6 +173,28 @@ module ActionView
# link_to "External link", "http://www.rubyonrails.org/", target: "_blank", rel: "nofollow" # link_to "External link", "http://www.rubyonrails.org/", target: "_blank", rel: "nofollow"
# # => <a href="http://www.rubyonrails.org/" target="_blank" rel="nofollow">External link</a> # # => <a href="http://www.rubyonrails.org/" target="_blank" rel="nofollow">External link</a>
# #
# ==== Turbo
#
# Rails 7 ships with Turbo enabled by default. Turbo provides the following +:data+ options:
#
# * <tt>turbo_method: symbol of HTTP verb</tt> - Performs a Turbo link visit
# with the given HTTP verb. Forms are recommended when performing non-+GET+ requests.
# Only use <tt>data-turbo-method</tt> where a form is not possible.
#
# * <tt>turbo_confirm: "question?"</tt> - Adds a confirmation dialog to the link with the
# given value.
#
# {Consult the Turbo Handbook for more information on the options
# above.}[https://turbo.hotwired.dev/handbook/drive#performing-visits-with-a-different-method]
#
# ===== \Examples
#
# link_to "Delete profile", @profile, data: { turbo_method: :delete }
# # => <a href="/profiles/1" data-turbo-method="delete">Delete profile</a>
#
# link_to "Visit Other Site", "https://rubyonrails.org/", data: { turbo_confirm: "Are you sure?" }
# # => <a href="https://rubyonrails.org/" data-turbo-confirm="Are you sure?">Visit Other Site</a>
#
# ==== Deprecated: \Rails UJS Attributes # ==== Deprecated: \Rails UJS Attributes
# #
# Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7, # Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
@ -224,9 +246,6 @@ module ActionView
# Generates a form containing a single button that submits to the URL created # Generates a form containing a single button that submits to the URL created
# by the set of +options+. This is the safest method to ensure links that # by the set of +options+. This is the safest method to ensure links that
# cause changes to your data are not triggered by search bots or accelerators. # cause changes to your data are not triggered by search bots or accelerators.
# If the HTML button does not work with your layout, you can also consider
# using the +link_to+ method with the <tt>:method</tt> modifier as described in
# the +link_to+ documentation.
# #
# You can control the form and button behavior with +html_options+. Most # You can control the form and button behavior with +html_options+. Most
# values in +html_options+ are passed through to the button element. For # values in +html_options+ are passed through to the button element. For
@ -240,6 +259,10 @@ module ActionView
# The form submits a POST request by default. You can specify a different # The form submits a POST request by default. You can specify a different
# HTTP verb via the +:method+ option within +html_options+. # HTTP verb via the +:method+ option within +html_options+.
# #
# If the HTML button generated from +button_to+ does not work with your layout, you can
# consider using the +link_to+ method with the +data-turbo-method+
# attribute as described in the +link_to+ documentation.
#
# ==== Options # ==== Options
# The +options+ hash accepts the same options as +url_for+. To generate a # The +options+ hash accepts the same options as +url_for+. To generate a
# <tt><form></tt> element without an <tt>[action]</tt> attribute, pass # <tt><form></tt> element without an <tt>[action]</tt> attribute, pass