Created: 2008-10-23 01:20
Updated: 2019-02-12 06:16
License: mit



This plugin was created to act as a proxy between different notification systems based on the user's preferences. IT DOESN'T IMPLEMENT ANY NOTIFICATION SYSTEM.


  1. Install the plugin with script/plugin install git://github.com/fnando/has_notifications.git

  2. Generate a migration with script/generate migration create_notifications and add the following code:

    class CreateNotifications < ActiveRecord::Migration def self.up create_table :notifications do |t| t.references :user t.string :name t.text :senders end

     add_index :notifications, :user_id
     add_index :notifications, :name


    def self.down drop_table :notifications end end

  3. Run the migrations with rake db:migrate


  1. Add association below to the User model:

    class User < ActiveRecord::Base has_many :notifications, :dependent => :destroy end

  2. Create user preferences for a specific notification

    create a new notification setting, specifying which

    senders will be associated

    notification = @user.notifications.create({ :name => 'friendship_request', :senders => %w(mail jabber) })

    deliver some message

    Notify.deliver({ :name => 'friendship_request, :user => @user, :friendship => @friendship })

  3. To implement a sender, you need to add a class to the module Notify::Senders. Check this example, that implements notification by mail using mail_queue


    class Notify::Senders::Mail < Notify::Base def deliver Mailer.queue(:some_email, @options) end end


    class Notify::Senders::Jabber < Notify::Base def deliver # using xmpp4r-simple set somewhere JABBER.deliver(@options[:user].jid, "You have new friendship request. Visit http://example.com/friends/pending" ) end end

A sender should have a deliver method. The options hash is set as instance attribute named @options.

Copyright (c) 2008 Nando Vieira, released under the MIT license

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more