I am trying to override Rails default confirm dialog box with [sweet-alert](https://github.com/mois3x/sweet-alert-rails-confirm). Below is the source JavaScript file, but I am running into an error which I can't seem to figure out.

It is returning the following Error:

```
 Uncaught TypeError: Cannot read property 'handleMethod' of undefined 

```

I think `$linkToVerify` is undefined, but I am not sure how to fix this. Can someone help?

```
(function( $ ) {
  var sweetAlertConfirm = function(event) {
    swalDefaultOptions = {
      title: 'Are you sure?',
      type: 'warning',
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Ok"
    }

    //this.click(function(event) {
    $linkToVerify = $(this)
    var swalOptions = swalDefaultOptions;
    var optionKeys = [
                       'confirm',
                       'text',
                       'type',
                       'showCancelButton',
                       'confirmButtonColor',
                       'cancelButtonColor',
                       'confirmButtonText',
                       'cancelButtonText',
                       'closeOnConfirm',
                       'imageUrl',
                       'allowOutsideClick',
                       'remote',
                       'method'
                     ]

    $.each($linkToVerify.data(), function(key, val) {
      if ($.inArray(key, optionKeys) >= 0) {
        swalOptions[key] = val
      }
    })

    message = $linkToVerify.attr('data-sweet-alert-confirm')
    swalOptions['title'] = message
    swal(swalOptions, function(r) {
      if (swalOptions['remote'] === true) { 
        $.rails.handleRemote($linkToVerify)
      }
      else if(swalOptions[ 'method' ] !== undefined) {
        $.rails.handleMethod($linkToVerify)
      }
      else {
        //[FIXME]Check this im not sure about this
        window.location.href = $linkToVerify.attr('href');
      }
    });

    return false;
  //});
  //return this;
  }

  $(document).ready(function() {
    //$("a[data-sweet-alert-confirm]").sweetAlertConfirm();
    $('a[data-sweet-alert-confirm]').on('click', sweetAlertConfirm)
  });

})( jQuery );

```