Hi, Dave. In my RoR 5 apps, I use this code (from StackOverflow, I guess :D)
```
$.rails.showConfirmationDialog = function (link) {
const message = link.data('confirm')
return swal(
{
title: message,
type: 'warning',
showCancelButton: true,
reverseButtons: true
}
).then(function (result) {
if (result.value) { return $.rails.confirmed(link) }
})
}
```
As you can see `return $.rails.confirmed(link)` makes the job. It works also with TurboLinks.
I don't know if this code should work with RoR 6.
Yea, it's really strange. On Rails 6, changing it remove the jQuery dependency, it doesn't work.
I updated your code to
```
Rails.showConfirmationDialog = function (link) {
const message = link.data('confirm')
return swal.fire(
{
title: message,
type: 'warning',
showCancelButton: true,
reverseButtons: true
}
).then(function (result) {
if (result.value) { return Rails.confirmed(link) }
})
}
```
and the javascript alert fires, but the SweetAlert doesn't. It has to be something with the `showConfirmationDialog` not getting set or fired properly.
And, changing the original code with your confirmed element instead of removing the data attribute doesn't work either. It's really strange.
`Rails.confirmed(element)`
Interesting. Despite your approach is weird, is good to have a solution for when I upgrade my app to v6.
I need to enhance my js skills before upgrading ;-)
This was really helpful and worked without issue. It's nice to have a current tutorial for Rails 6 and Webpack. Thanks :-) Two questions to take this further:
1) How can one distinguish between multiple data confirms on the same page?
2) How can this be made page specific?
Hi thanks for the video, it worked perfectly! I was just wondering if there is a way of having a success notification after an item is successfully edited saying "item edited successfully" when it returns to the item page. Thanks again.
I was just wondering if there is a way of having a success notification after an item is successfully edited saying "item edited successfully" when it returns to the item page.
Thanks again.