This gem allows you to use SweetAlert or SweetAlert2 for your flash messages. See the examples below, to see how to use it
Note: This package does not provide the client-side files of SweetAlert. You have to provide them yourself.
Add this line to your application's Gemfile:
gem'sweetify'And then execute:
$ bundleNext up, create the file sweetify.rb in your initializers to specify the library you are using (SweetAlert or SweetAlert2):
# possible options: 'sweetalert', 'sweetalert2' - default is 'sweetalert2'Sweetify.sweetalert_library='sweetalert2'Next add the following line to the bottom of your application's layout file:
...
<%= render 'sweetify/alert' %></body></html>You have to restart your rails server after installing the gem
You can now easily create alerts in your controllers with any of the following methods provided by Sweetify:
# Base Method, no type specifiedsweetalert(text,title='',opts={})# Additional methods with the type already definedsweetalert_info(text,title='',opts={})sweetalert_success(text,title='',opts={})sweetalert_error(text,title='',opts={})sweetalert_warning(text,title='',opts={})# POST /resourcedefcreatesweetalert_success('Your resource is created and available.','Successfully created',persistent: 'Awesome!')redirect_toresource_pathendThat would look like this after the redirect:
By default, all alerts will dismiss after a sensible default number of seconds.
Default Options set by Sweetify:
{showConfirmButton: false,timer: 2000,allowOutsideClick: true,confirmButtonText: 'OK'}The following special options provided by Sweetify are available:
# Shows the alert with a button, but will still close automaticallysweetalert('Text','Title',button: true)sweetalert('Text','Title',button: 'Awesome!')# Custom text for the button# Shows the alert with a button and only closes if the button is pressedsweetalert('Text','Title',persistent: true)sweetalert('Text','Title',persistent: 'Awesome!')# Custom text for the buttonYou also can use any other available option that SweetAlert accepts:
sweetalert_info('Here is a custom image','Sweet!',imageUrl: 'images/thumbs-up.jpg',timer: 5000)Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
