Skip to content

Commit

Permalink
Merge pull request #47505 from julianfssen/update-api-link-to-button-…
Browse files Browse the repository at this point in the history
…to-turbo

Add docs for `data-turbo-method` and `data-turbo-confirm` for `link_to`
  • Loading branch information
rafaelfranca committed Aug 21, 2023
2 parents 7797681 + 6a798d0 commit ae20b0d
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions actionview/lib/action_view/helpers/url_helper.rb
Expand Up @@ -173,6 +173,28 @@ def _filtered_referrer # :nodoc:
# 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>
#
# ==== 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
#
# Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
Expand Down Expand Up @@ -224,9 +246,6 @@ def link_to(name = nil, options = nil, html_options = nil, &block)
# 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
# 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
# values in +html_options+ are passed through to the button element. For
Expand All @@ -240,6 +259,10 @@ def link_to(name = nil, options = nil, html_options = nil, &block)
# The form submits a POST request by default. You can specify a different
# 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
# The +options+ hash accepts the same options as +url_for+. To generate a
# <tt><form></tt> element without an <tt>[action]</tt> attribute, pass
Expand Down

0 comments on commit ae20b0d

Please sign in to comment.