需要评论-nano
这个 neeto-comments-nano 管理应用程序中的评论, 通知
根据用户的喜好通过电子邮件提及用户.
目录
用主机应用程序开发
发动机
引擎处理注释表的后端并通知首选 在创建新评论时,用户通过电子邮件.
安装
-
将此行添加到您的应用程序的 Gemfile 中 :
source "NEETO_GEM_SERVER_URL" do # ..existing gems gem "neeto-comments-engine" end -
然后执行:
bundle install -
将此行添加到您的应用程序
config/routes.rb文件 :mount NeetoCommentsEngine::Engine, at: "/neeto_comments" -
运行命令以将所需的全部迁移从引擎带入 主机应用程序 :
bundle exec rails neeto_comments_engine:install:migrations -
添加迁移到数据库 :
bundle exec rails db:migrate
使用量
型号
Neeto 评论引擎: Comment (源代码(中文(简体) )
这个模型有以下多态性关联
belongs_to :commentable, polymorphic: true
belongs_to :creator, polymorphic: true
这里, commentable 是我们要添加评论的实体。 例如,在
NeetoPlanner, (中文(简体) ), Task 是可评论的实体。 我们可以在任务中添加注释如下:
如下:
has_many :comments, as: :commentable, dependent: :destroy
同样 creator 是创建注释的实体.
在主机应用程序中,我们可以使用 Comment 模式的继承
如下:
class Comment < NeetoCommentsEngine::Comment
self.table_name = "neeto_comments_engine_comments"
end
主机应用程序的继承模式需要下列方法: 创建注释后立即通知注释中提到的用户 :
def email_data
{
preference_link:, # Notification preference URL
organization_name:,
link_title:, # Title
subject:, # Subject
reply_to: # Reply to email
}
end
这个 get_mentioned_ids_from_content 方法返回
提及需要通知和可以使用的用户如下:
def notifiable_users
user_list = get_mentioned_ids_from_content(content)
User.where(id: user_list)
end
主计长
Neeto 评论引擎: Api: V1:: 评论控制器( )源代码(中文(简体) )
在主机应用程序中,我们可以继承 CommentsController 内容如下:
class Api::V1::CommentsController < NeetoCommentsEngine::Api::V1::CommentsController
private
def load_commentable!
# required method in the host application to load the commentable entity
end
end
关切
Neeto 评论引擎: 通知 首选项( E)源代码(中文(简体) )
包括下列关切: commentable 模式
include NeetoCommentsEngine::NotificationPreferences
这个 notify_mentioned_user?(user) 返回布尔值,以决定是否
发送电子邮件给用户与否。 默认返回方法 true这个
可被主机应用程序所覆盖.
def notify_mentioned_user?(user)
true
end
这个 notify_mentions_via_email? 返回布尔值,以决定是否
发送电子邮件给该可评论实体与否。 默认返回方法
true。这可以被主机应用程序所覆盖.
def notify_mentions_via_email?
true
end
出版指令
咨询 构建和释放软件包 关于如何出版的详细指南.