Notifications Center engine like GitHub or other application for any Rails applications.
Notifications Center engine like GitHub or other application for any Rails applications.
Mountable notifications for any Rails applications.
$ bundle add notificationsYou now have a notifications generator in your Rails application:
$ rails g notifications:installYou can generate views, controllers if you need to customize them:
$ rails g notifications:views
$ rails g notifications:controllersclass User
def follow(user)
Notification.create(notify_type: 'follow', actor: self, user: user)
end
end
class Comment
belongs_to :post
belongs_to :user
after_commit :create_notifications, on: [:create]
def create_notifications
Notification.create(
notify_type: 'comment',
actor: self.user,
user: self.post.user,
target: self)
end
endGet unread notifications count for a user:
# unread count
unread_count = Notification.unread_count(current_user)
# read count
read_count = Notification.read_count(current_user)
…If you create a notify_type, you need to add a partial view in app/views/notifications/ path, for example:
# There have two notify_type
Notification.create(notify_type: 'follow' ....)
Notification.create(notify_type: 'mention', target: @reply, second_target: @topic, ....)Your app must have:
# app/views/notifications/_follow.html.erb
# app/views/notifications/_mention.html.erb
NOTE: When you want use Rails route path name in notification views, you must use main_app prefix. etc:
main_app.user_path(user)
It is recommended that you use second_level_cache for solving N+1 performance issues.
Testing for multiple Rails versions:
make test_51
# or test all
make testThe gem is available as open source under the terms of the MIT License.
No open issues yet, or sync has not completed.