1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

update delete example using turbo

This commit is contained in:
condef5 2021-12-19 22:06:07 -05:00
parent 6c16b7e97d
commit 58d66cfc75

View file

@ -1306,17 +1306,16 @@ we can delete an article from its own page:
<ul> <ul>
<li><%= link_to "Edit", edit_article_path(@article) %></li> <li><%= link_to "Edit", edit_article_path(@article) %></li>
<li><%= link_to "Destroy", article_path(@article), <li><%= link_to "Destroy", article_path(@article),
method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></li>
data: { confirm: "Are you sure?" } %></li>
</ul> </ul>
``` ```
In the above code, we're passing a few additional options to `link_to`. The In the above code, we're passing the `data` attribute with some options to `link_to`.
`method: :delete` option causes the link to make a `DELETE` request instead of a The `turbo_method: :delete` option causes the link to make a `DELETE` request instead
`GET` request. The `data: { confirm: "Are you sure?" }` option causes a of a `GET` request. The `turbo_confirm: { confirm: "Are you sure?" }` option causes a
confirmation dialog to appear when the link is clicked. If the user cancels the confirmation dialog to appear when the link is clicked. If the user cancels the
dialog, the request is aborted. Both of these options are powered by a feature dialog, the request is aborted. Both of these options are powered by (Turbo)[https://turbo.hotwired.dev/]
of Rails called *Unobtrusive JavaScript* (UJS). The JavaScript file that called *Performing Visits*. The JavaScript file that
implements these behaviors is included by default in fresh Rails applications. implements these behaviors is included by default in fresh Rails applications.
TIP: To learn more about Unobtrusive JavaScript, see [Working With JavaScript in TIP: To learn more about Unobtrusive JavaScript, see [Working With JavaScript in
@ -1500,8 +1499,7 @@ So first, we'll wire up the Article show template
<ul> <ul>
<li><%= link_to "Edit", edit_article_path(@article) %></li> <li><%= link_to "Edit", edit_article_path(@article) %></li>
<li><%= link_to "Destroy", article_path(@article), <li><%= link_to "Destroy", article_path(@article),
method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></li>
data: { confirm: "Are you sure?" } %></li>
</ul> </ul>
<h2>Add a comment:</h2> <h2>Add a comment:</h2>
@ -1566,8 +1564,7 @@ add that to the `app/views/articles/show.html.erb`.
<ul> <ul>
<li><%= link_to "Edit", edit_article_path(@article) %></li> <li><%= link_to "Edit", edit_article_path(@article) %></li>
<li><%= link_to "Destroy", article_path(@article), <li><%= link_to "Destroy", article_path(@article),
method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></li>
data: { confirm: "Are you sure?" } %></li>
</ul> </ul>
<h2>Comments</h2> <h2>Comments</h2>
@ -1640,8 +1637,7 @@ following:
<ul> <ul>
<li><%= link_to "Edit", edit_article_path(@article) %></li> <li><%= link_to "Edit", edit_article_path(@article) %></li>
<li><%= link_to "Destroy", article_path(@article), <li><%= link_to "Destroy", article_path(@article),
method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></li>
data: { confirm: "Are you sure?" } %></li>
</ul> </ul>
<h2>Comments</h2> <h2>Comments</h2>
@ -1700,8 +1696,7 @@ Then you make the `app/views/articles/show.html.erb` look like the following:
<ul> <ul>
<li><%= link_to "Edit", edit_article_path(@article) %></li> <li><%= link_to "Edit", edit_article_path(@article) %></li>
<li><%= link_to "Destroy", article_path(@article), <li><%= link_to "Destroy", article_path(@article),
method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></li>
data: { confirm: "Are you sure?" } %></li>
</ul> </ul>
<h2>Comments</h2> <h2>Comments</h2>