Reputation: 5940
New Rails 7 app created in 2021 or 2022, when I click on a form with data-turbo-confirm
, the alert message does not show.
<%= form_with url: root_path(), data: {'turbo-confirm': "Are you sure you want to submit this form?"},
method: :delete do |f| %>
<%= f.submit "Delete".html_safe, class: "delete-apple-button btn btn-primary btn-sm" %>
<% end %>
<br />
<%= turbo_frame_tag "apples-list" do %>
nothing has happened yet
<% end %>
Page loads to:
When you click delete, no alert is shown:
Expected result: • Alert message confirming the button action
Actual result: • No alert is shown
Upvotes: 11
Views: 5443
Reputation: 41
I ran into this same problem when doing the Ruby on Rails guide here.
Somewhere along the way of me trying things, I stumbled upon mention of the turbo-rails
gem. I found a working solution with these pieces:
application.html.erb
file:
<%= javascript_include_tag "turbo", type: "module" %>
gem "turbo-rails", "~> 1.0"
to your Gemfilebundle install
bin/rails turbo:install
Using these steps, the code from the rails guide works, along with the confirmation dialog. 🎉
Upvotes: 0
Reputation: 29
you can use js to do this.
the code is work for me.
function confirmDestroy(message) {
if (!confirm(message)) {
return false;
}
}
<div>
<%= link_to "Edit this post", edit_post_path(@post) %> |
<%= link_to "Back to posts", posts_path %>
<%= button_to "Destroy this post", @post, method: :delete, onclick: "return confirmDestroy('Are you sure want destroy this post?')" %>
</div>
Upvotes: 1
Reputation: 5940
This happens if you had locally installed gem versions 7.1.0 or 7.1.1 for turbo-rails
These gem numbers were pushed by accident to Rubygems in October, then yanked. However, since bundler will default to the highest number of your Rails gem when it sets up your new rails app, it will pick turbo-rails version 7.1.0 or 7.1.1 , which will display this flaw
The gems were yanked, so this only affects you if you were developing rails apps between October 2021 and the yank date.
TO FIX YOUR COMPUTER:
gem uninstall turbo-rails
Bundler will prompt you for which version to uninstall:
You will need to repeat this step if you have both gem versions installed.
Then, bundler will not make new apps with that version.
However, if you generated an app already it will be locked to the wrong version. to fix, specify version explicitly in Gemfile
gem "turbo-rails", "~> 1.0"
Upvotes: 1