Rails mountable Notification for any applications.

Gem Version Build Status Code Climate


2016-03-29 10 48 16


ruby # Gemfile gem 'notifications'

And then run bundle install.

Now you have notifications generator in Rails application:

bash $ rails g notifications:install

And, you can generate views, controller if you need custom them:

bash $ rails g notifications:views $ rails g notifications:controllers


Create a Notification

```ruby class User def follow(user) Notification.create(notify_type: ‘follow’, actor: self, user: user) end end

class Comment belongs_to :post belongs_user :user

after_commit :create_notifications, on: [:create] def create_notifications Notification.create( notify_type: ‘comment’, actor: self.user, user:, target: self) end end ```

Get user unread count:

rb count = Notification.unread_count(current_user)

Write your custom Notification partial view for notify_types:

If you create a notify_type, you need add a partial view in app/views/notifications/ path, for example:

rb # There have two notify_type Notification.create(notify_type: 'follow' ....) Notification.create(notify_type: 'mention', target: @reply, second_target: @topic, ....)

You app must be have:

  • app/views/notifications/_follow.html.erb
  • app/views/notifications/_mention.html.erb

erb # app/views/notifications/_follow.html.erb <div class="media-heading"> <%= link_to, %> just followed you. </div>

erb # app/views/notifications/_mention.html.erb <div class="media-heading"> <%= link_to, %> has mention you in <%= link_to notification.second_target.title, topic_path(notification.second_target) %> </div> <div class="media-content"> <%= %> </div>

About Notification template N+1 performance

Suggest you to use second_level_cache for solve N+1 performance issue.


Contribution directions go here.

Site Used


The gem is available as open source under the terms of the MIT License.