New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for data-turbo-method
and data-turbo-confirm
for link_to
#47505
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This links back to the documentation I added for |
||
# | ||
# ==== 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example should probably be a
button_to
. Is there a more appropriate example we can use here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, @ghiculescu ! I've added an expanded example of
button_to
that fails, and a short explanation on whylink_to
withdata-turbo-method
should be used instead in this commit: 1e568cd