在rails中向用户发表评论通知? [英] Comment notification to users in rails?

查看:116
本文介绍了在rails中向用户发表评论通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的webapp有注册用户,它有文章,博客文章,闲话太。
对于所有这些资源,我有一个多态的注释模型,如下所示。

my webapp has registered users and it has articles, blog posts, gossips too. For all these resources I've a polymorphic Comment model which is listed below.

id  content         commentable_id  commentable_type   user_id  created_at  updated_at
1   Frist comment   2               Article            1        ....
2   Second comment  3               Post               2        .....

因此,对于每个可注释的资源,我在注释资源的底部有一个注释表单,供用户评论。
我想要一个复选框,当提交评论时选中,用户应该收到一个通知,无论是在收件箱或电子邮件,因为我们已经在用户注册,以后其他新的评论时添加。

So for each commentable resource, I've a comment form at the bottom of the commentable resource for users to comment. I want a checkbox, when checked while submitting the comment, the users should receive a notification, be it in Inbox or email since we already have it on user signup, when other new comments are added later.

我想有一些模型像通知,我可以存储commentable_type,commentable_id和user_id(如果有任何新的评论创建与匹配的可评论和用户?

I want to have some model like Notifications where I could store the commentable_type, commentable_id and user_id (to whom the notification should be sent if there is any new comment created with the matching commentable and user?

如何实现注释和通知之间的关联?对于检查部分,如果有任何一个订阅特定的可注释资源,则创建一个CommentObserver with after_create hook如果有任何匹配的记录,则初始化搜索并发送通知。

How can I implement the association between Comment and Notification? For the checking part if there is any one subscribe to the particular commentable resource is create a CommentObserver with after_create hook to initialize the search and send notifications if there is any matching record.

但是我很困惑什么关联,模型,控制器和视图来完成这个?注释模型已经是多态的,我可以创建Notification模型作为多态吗?

But I'm confused what the association, model, controller and views would look like to accomplish this? Since the comment model is already polymorphic, can I create the Notification model as polymorphic too??

推荐答案

插入。
创建数据库表以存储帖子的用户通知订阅。然后,每次创建注释时,查询数据库并使用 ActionMailer a>到所有用户的地址。

You can easily accomplish this without a plugin. Create a database table to store User notification subscriptions for posts. Then, each time you create a comment, query the database and send an email using ActionMailer to all users' address.

这篇关于在rails中向用户发表评论通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆