-
Notifications
You must be signed in to change notification settings - Fork 508
Rails flash integration with PNotify
Ahmad Musaffa edited this page Sep 1, 2014
·
3 revisions
Follow the instructions to setup pnotify-rails gem.
Or you can use rails-assets to use Pnotify's git repository as the source. To do this:
- add
source 'https://rails-assets.org'below rubygem source declaration in theGemfile. - add
gem 'rails-assets-pnotify' - run
bundle install - add
//= require pnotifyinaplication.js - add
//= require pnotifyinapplication.css
- install unobtrusive_flash gem.
- add
//= require unobtrusive_flashinapplication.js
- add
after_filter :prepare_unobtrusive_flashto the top of the controllers that contain flashes. Or you can add this to the application controller as a global controller callback. - define flashes in the controller actions as usual.
Remove any code in the views related to the flashes.
Add a flashes.js in the javascript assets directory:
// flashes.js
$(document).ready(function() {
$(window).bind('rails:flash', function(e, params) {
new PNotify({
title: params.type,
text: params.message,
type: params.type
});
});
});Now require flashes.js in the application.js. Remember to put it below require pnotify and require unobtrusive_flash.
Restart the server. Now You can Play!
If you need I18n in javascript, checkout i18n-js.