针对 Ruby on Rails 的集成用户活动通知
activity_notification provides integrated user activity notifications for Ruby on Rails. You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
activity_notification supports Rails 7.0+ with ActiveRecord, Mongoid and Dynamoid ORM. It is tested for MySQL, PostgreSQL, SQLite3 with ActiveRecord, MongoDB with Mongoid and Amazon DynamoDB with Dynamoid v3.11.0+. If you are using Rails 5 or Rails 6, use v2.3.3 or older version of activity_notification.
activity_notification provides following functions:
activity_notification deeply uses PublicActivity as reference in presentation layer.
REST API reference as OpenAPI Specification is published in SwaggerHub here:
You can see sample single page application using Vue.js as a part of example Rails application in /spec/rails_app. This sample application works with activity_notification REST API backend.
This getting started shows easy setup description of activity_notification. See Setup for more details.
You can install activity_notification as you would any other gem:
$ gem install activity_notificationor in your Gemfile:
gem 'activity_notification'After you install activity_notification and add it to your Gemfile, you need to run the generator:
$ bin/rails generate activity_notification:installThe generator will install an initializer which describes all configuration options of activity_notification.
By default, activity_notification uses ActiveRecord as the ORM and no additional ORM gems are required.
If you intend to use Mongoid support, you need to add the mongoid gem separately to your Gemfile:
gem 'activity_notification'
gem 'mongoid', '>= 4.0.0', '= 3.11.0', '(comment, key) {
([comment.article.user] + comment.article.reload.commented_users.to_a - [comment.user]).uniq
},
notifiable_path: :article_notifiable_path
def article_notifiable_path
article_path(article)
end
endSee Configuring models for more details.
activity_notification provides view templates to customize your notification views. See Configuring views for more details.
activity_notification also provides routing helper for notifications. Add notify_to method to config/routes.rb for the target (e.g. :users):
Rails.application.routes.draw do
notify_to :users
endSee Configuring routes for more details.
You can also configure activity_notification routes as REST API backend with api_mode option like this:
Rails.application.routes.draw do
scope :api do
scope :"v2" do
notify_to :users, api_mode: true
end
end
endSee Routes as REST API backend and REST API backend for more details.
You can trigger notifications by setting all your required parameters and triggering notify on the notifiable model, like this:
@comment.notify :users, key: "comment.reply"The first argument is the plural symbol name of your target model, which is configured in notifiable model by *acts_as_not
暂无开放 Issues,或尚未同步最近议题。