Skip to content

Linter Rule: Prefer data-turbo-confirm over the deprecated data-confirm

Rule: ujs-prefer-turbo-confirm

Description

Disallow the data-confirm attribute and the Action View helper option that renders it, data: { confirm: ... }. Use data-turbo-confirm or data: { turbo_confirm: ... } instead.

Rationale

Before Rails 7, Rails shipped @rails/ujs by default, which added JavaScript behavior to elements through helper options and data-* attributes. Rails 7 stopped including it, and Turbo covers the same behavior with its own attributes.

data-confirm made @rails/ujs prompt the user with the given question before proceeding, and cancel the action if the user declined. data-turbo-confirm is a drop-in replacement, so the migration is mechanical.

Once @rails/ujs is gone the attribute is inert, and the failure is silent rather than loud: the link or button still works, but the confirmation prompt simply stops appearing. A destructive action that was guarded now fires on the first click.

Examples

✅ Good

erb
<a href="/posts/1" data-turbo-confirm="Are you sure?">Delete</a>
erb
<%= link_to "Delete", post_path(@post), data: { turbo_confirm: "Are you sure?" } %>
erb
<%= button_to "Delete", post_path(@post), data: { turbo_confirm: "Are you sure?" } %>

🚫 Bad

erb
<a href="/posts/1" data-confirm="Are you sure?">Delete</a>
Avoid the deprecated `@rails/ujs` attribute `data-confirm`. Use `data-turbo-confirm` instead. (ujs-prefer-turbo-confirm)
erb
<%= link_to "Delete", post_path(@post), data: { confirm: "Are you sure?" } %>
Avoid the deprecated `@rails/ujs` option, which renders `data-confirm`. Use `data: { turbo_confirm: ... }` instead. (ujs-prefer-turbo-confirm)
erb
<%= button_to "Delete", post_path(@post), data: { confirm: "Are you sure?" } %>
Avoid the deprecated `@rails/ujs` option, which renders `data-confirm`. Use `data: { turbo_confirm: ... }` instead. (ujs-prefer-turbo-confirm)

References

Released under the MIT License.