Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Created October 21, 2014 16:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oshuma/23b223a22cefd347f638 to your computer and use it in GitHub Desktop.
Save Oshuma/23b223a22cefd347f638 to your computer and use it in GitHub Desktop.
Use sweetAlert with Rails UJS.
$.rails.allowAction = function(link) {
if ( ! link.attr('data-confirm') ) return true;
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
link.trigger('click.rails');
};
$.rails.showConfirmDialog = function(link) {
sweetAlert({
title: link.attr('data-confirm'),
showCancelButton: true
}, function(isConfirmed) {
if (isConfirmed) $.rails.confirmed(link);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment