Socket
Book a DemoInstallSign in
Socket

sweet-alert2-rails

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sweet-alert2-rails

bundlerRubygems
Version
0.1.0
Version published
Maintainers
1
Created
Source

sweet-alert2-rails

This library easily integrates the SweetAlert 2 library into a Rails application.

Using the same Rails markup :

  = link_to 'Delete', item, method: :delete, data: { confirm: 'Are you sure you want to delete this item?' }

You go from:

before

To:

after

It is heavily based on the work from Moises Viloria with SweetAlert. Some cleaning and refactoring were made to make it compatible with SweetAlert 2.

It replaces the browser confirm dialog when using data: { confirm: 'message' } with the link_to helper with a nice looking sweet alert.

Requirements

Rails >= 4.2, tested with Rails 5

Usage

Add the SweetAlert2 and sweet-alert2-rails to your Gemfile:

gem 'rails-assets-sweetalert2', '~> 5.1.1', source: 'https://rails-assets.org'
gem 'sweet-alert2-rails'

Add the following to application.js:

//= require sweetalert2
//= require sweet-alert2-rails

Add the following to application.css:

/*
 *= require sweetalert2
 */

Try it:

  = link_to "Delete", user, method: :delete, data: { confirm: 'Are you sure?' }

Custom options

You may pass options in data:

 data: {
  confirm: 'Are you ready?',
  'confirm-button-text': 'Im ready',
  'cancel-button-text': 'No way',
  'confirm-button-color': '#66CD00',
  'sweet-alert-type': 'info',
  text: 'This is a subtitle',
  'image-url': '/pic.png'
}

Default options that will be used application wide so it is not necessary to set the option on each link. Put this object inside your app to override default options with the sweetAlertConfirmConfig object.

window.sweetAlertConfirmConfig = {
  title: 'Are you sure?',
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#DD6B55',
  confirmButtonText: 'Ok'
};

Contribute

Fork the repo & make a pull request with your fix or feature. Thanks :).

FAQs

Package last updated on 30 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts