I'm currently facing a problem in my project. I'm on Rails 6.0.4.8 and Ruby 2.6.8.
The issue I'm running into is that I would like a user to be able to delete a notes record by clicking on an icon but when they click on this icon, I'd like this to open up a modal that asks them "Are you sure you want to delete this note?"
However the modal isn't popping up and it's going straight to deleting the record: NotesController's destroy method. This is the code in my views that I'm trying to fix:
# Where note is being passed in because I am iterating through @notes.each |note| to create <tr> elements with link_to's
# Using FontAwesome and SweetAlert
<%= link_to '<i class="fa fa-remove text-danger"></i>'.html_safe, note_path(note),
method: :delete, data: {
confirm: 'Are you sure you want to delete this note?',
:'confirm-button-text' => 'Yes, delete this note',
:'cancel-button-text' => 'No, keep this note',
:'confirm-button-color' => '#BA3525',
:'sweet-alert-type' => 'warning',
} %>
This is resulting in the confirmation modal never appearing.
I've tried:
- changing
link_totobutton_tobut this just erases the icon from appearing and still results in the modal not popping up. - wrapping
datainsideformlike so:form: { data: confirm: 'Are you sure?' } - changing
confirmtoturbo_confirm(obviously didn't work, but was a longshot because that works for me in Rails 7)
Nothing works so far and I'd like some help ensuring a confirmation before any deletion.