百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

notifications

> 后端框架
开源

通知中心引擎,例如 GitHub 或其他用于任何 Rails 应用程序的应用程序。

382 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

通知中心引擎,例如 GitHub 或其他用于任何 Rails 应用程序的应用程序。

Notifications

Mountable notifications for any Rails applications.

Example:

Installation

bash
$ bundle add notifications

You now have a notifications generator in your Rails application:

bash
$ rails g notifications:install

You can generate views, controllers if you need to customize them:

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

Usage

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_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
end

Get unread notifications count for a user:

rb
# unread count
unread_count = Notification.unread_count(current_user)

# read count
read_count = Notification.read_count(current_user)
…

Write your custom Notification partial view for notify_types:

If you create a notify_type, you need to 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, ....)

Your app must have:

  • app/views/notifications/_follow.html.erb
  • app/views/notifications/_mention.html.erb
erb
# app/views/notifications/_follow.html.erb
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)

About Notification template N+1 performance

It is recommended that you use second_level_cache for solving N+1 performance issues.

Contributing

Testing for multiple Rails versions:

bash
make test_51
# or test all
make test

Site Used

  • Ruby China

License

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubynotificationnotification-centernotificationsrails-engine

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架