📜 ⬆️ ⬇️

Pop-up flash message from the depths of background tasks

Every time you need to display a flash message, you encounter the same problems: it’s not clear where to display these messages, we will define a place on the page in advance on the page, which is pathetic, make a stretchable design that is not always convenient. And there can be a lot of these messages, and still everyone tries to keep them under his key (warning, notice ..). When it was necessary to send messages to the user from delayed_job, it became clear that you need to solve this problem once and for all.

gem gritter_notice - displays flash and conveniently processes pop-up messages stored in the database in 5 lines of code.

image
')

Visual example: boedesign.com/demos/gritter

Installation:



We connect modules in Gemfile

 gem 'gritter' # Do not forget to install js, css and image files according to its instructions
 gem 'gritter_notice'


Create a gritter_notices table

     rails g gritter_notices
     rake db: migrate


We connect to notices in the user model:

     class User <ActiveRecord :: Base
     has_gritter_notices


In the layout, do this (haml-example):
  % head
     = include_gritter
  % body
     = gritter_flash_messages


Using



 user.notice 'Just a text message'
 # Show a simple text message

 user.notice 'Text message',: level =>: error,: sticky => true
 # The message will freeze until it is closed.


Learn more: github.com/dapi/gritter_notices

Source: https://habr.com/ru/post/116754/


All Articles