Project

flyer

0.0
No commit activity in last 3 years
No release in over 3 years
Display user notifications in Rails programmatically
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 4.0
 Project Readme

Flyer

Display user notifications in Rails programmatically.

Install

gem install flyer

Usage

# config/initializers/flyer.rb
# Use one init block for each notification
Flyer::Notification.init do |config|
  # Unique id. Used to uniquely identify a notification.
  config.id = "new-user"

  # Message to be passed to view. Is evaluated in the view context.
  config.message { "Your nickname is #{current_user.nickname}" + icon("flash") }

  # Optional. Path to be pssed to view. Is evaluated in the controller context.
  config.path { root_path }

  # Optional. Only display notification if this blocks evaluates to true
  # The block is evaluated in the controller context.
  config.on { current_user.admin? and not first_visit? }

  # Optional. Number of times to display the notification 
  # for each user. Default is 1.
  config.limit = 1

  # Optional. When should the notification be visible?
  config.valid = { from: "2015-04-01", to: "2016-04-01" }

  # Optional. Arbitrary data to be passed to view. 
  config.params = { timeout: 10 }
end

# Global configuration
Flyer.configure do |config|
  # Only display one notification at the time
  config.max_notifications = 1
end
-- app/views/_notifications.html.erb (any view)
<% notifications.each do |notification| %>
  <%= notification.path %>
  <%= notification.message %>
  <%= notification.params %>
<% end %>