I got stuck when using turbo_confirm
on form.submit
button in my new Rails 7 app. The following does not show the confirmation dialog with Turbo while the action renders correctly.
<%= form_with(url: check_path) do |form| %>
<%= text_area_tag(
:typotext,
@received_string,
class: 'form-control font-monospace'
)
%>
<%= form.submit 'Submit',
class: "btn btn-primary",
data: { turbo_confirm: 'Are you sure?' }
%>
<% end %>
Finally I found that the following works (via New Rails 7 Turbo app doesn't show the data-turbo-confirm alert messages don't fire (turbo-rails 7.1.0 and 7.1.1) - Stack Overflow ).
I got a bit surprised that { turbo_confirm: 'Are you sure?' }
should be added to form_with
, instead of form.submit
(or submit_tag
or form.button
).
<%= form_with(url: check_path, data: { turbo_confirm: 'Are you sure?' }) do |form| %>
<%= text_area_tag(
:typotext,
@received_string,
class: 'form-control font-monospace'
)
%>
<%= form.submit 'Submit',
class: "btn btn-primary"
%>
<% end %>
FYI: In the controller action, I added status: :accepted
for Turbo (jbuilder has been disabled in my app).
def check
flash[:info] = 'OK'
# do something
render :check, status: :accepted
end
end
I just wonder if this is expected and correct (I could not find the ones in current Rails Guides or API docs).