Handle notification creation and distribution
Ruby JavaScript
Switch branches/tags
Nothing to show



Build Status

ActsAsNotifiable aims to be a flexibile notification system for your Rails application. On social networks, notifications can be sent from any kind of action. ActsAsNotifiable has 2 goals:

  1. Centralize the creation of notifications on different objects in a system
  2. Provide a modular way to deliver these notifications across various methods


Some examples of various things that may generate a notification include:

  • A user follows another user
  • A user comments on another user's post
  • A user likes a post



RDocs for ActsAsNotifiable are available online here:



As systems become larger and users have more ways to receive notifications, a flexibile delivery system is needed. ActsAsNotifiable couriers will do just this.

Example couriers:

  • Email
  • Apple Push Notification
  • SMS

Example Usage

First, you will need a model to hold notifications.

class Notification < ActiveRecord::Base
	include ActsAsNotifiable::Notification

A notification has the following properties:

belongs_to :sender, polymorphic: true
belongs_to :receiver, polymorphic: true
belongs_to :notifiable: polymorphic: true
belongs_to :target, polymorphic: true


With a base notification class in place we can start generating notifications for a user.

class Author < ActiveRecord::Base
  has_many :posts

  # Set up relations to accept notifications

class Post < ActiveRecord::Base
	has_many :comments
	belongs_to :author

class Comment < ActiveRecord::Base
  # Comments are notifiable, they will send notifications out when created
	notifiable receiver: lambda { |c| c.post.author }, sender: :author

  # Specify a courier to send notifications, in this case email
	notify_via :email
	belongs_to :author
	belongs_to :post

Whenever a comment is created, the author of the post the comment belongs to will receive a notification notifying them that the comment author commented on their post.

notify_via specifies any couriers to use to deliver this notification, in this case an email will be generated.


  • Document advanced usage
  • Abstract APNS courier out
  • Example courier creation
  • Refactor ActsAsNotifiable::Notification


MIT License. Copyright 2012 QFive, Inc. http://www.qfive.com