我的 webapp 已经注册了用户,它也有文章、博客文章、八卦。对于所有这些资源,我有一个多态评论模型,如下所示。
id content commentable_id commentable_type user_id created_at updated_at
1 Frist comment 2 Article 1 ....
2 Second comment 3 Post 2 .....
因此,对于每个可评论资源,我在可评论资源的底部都有一个评论表单供用户评论。我想要一个复选框,在提交评论时选中时,用户应该会收到通知,无论是在收件箱还是电子邮件中,因为我们已经在用户注册时拥有它,稍后会添加其他新评论。
我想要一些模型,比如 Notifications,我可以在其中存储 commentable_type、commentable_id 和 user_id(如果使用匹配的可评论和用户创建了任何新评论,应该向谁发送通知?
如何实现 Comment 和 Notification 之间的关联?对于检查部分,如果有任何人订阅了特定的可评论资源,则使用 after_create 钩子创建一个 CommentObserver 来初始化搜索并在有任何匹配记录时发送通知。
但我很困惑关联、模型、控制器和视图会是什么样子来完成这个?由于评论模型已经是多态的,我可以将通知模型创建为多态吗?