简体   繁体   English

Rails - Action Mailer约定

[英]Rails — Action Mailer conventions

Thinking about implementing of (a little bit) smarter notification system in my project. 考虑在我的项目中实施(一点点)智能通知系统。 What I'd like to do is emailing user about few new let's say private messages once within certain range of time rather than each time he gets new message. 我想要做的是电子邮件用户关于一些新的假设,一旦在每个他得到新的消息时,一定范围内的时间,而不是私人信息。 Of course there will not be without delayed_job , but here I've got a couple of etic questions about ActionMailer: 当然不会没有delayed_job ,但在这里我有一些关于ActionMailer的问题:

  1. How many logic you can put in Mailer class? 您可以在Mailer课程中添加多少逻辑?
  2. Can I perform database queries within Mailer class methods? 我可以在Mailer类方法中执行数据库查询吗?

So you'll be sending an email "Digest" of the various "Notifications" that occur in the system. 因此,您将发送系统中出现的各种“通知”的电子邮件“摘要”。

I suggest you move the logic that right now sends an email using ActionMailer to a Notification class. 我建议你移动现在使用ActionMailer向Notification类发送电子邮件的逻辑。 This will persist the notification with a flag set to false for notified (or similar). 对于notified (或类似),这将持续通知标志设置为false。

Then, have a job run daily (or similar) that sends a digest email to people who have notifications they need to receive. 然后,每天(或类似)运行一个作业,向需要收到通知的人发送摘要电子邮件。

I would suggest keeping ActionMailer logic to a bare minimum: just rendering the email and doing the actual delivery. 我建议将ActionMailer逻辑保持在最低限度:只需渲染电子邮件并进行实际交付。

Yes I realize this makes the delayed_job logic slightly more complicated since you can't just send a delayed email, but it keeps the logic where it should be. 是的,我意识到这会使delayed_job逻辑稍微复杂一些,因为你不能只发送一个延迟的电子邮件,但它保留了它应该存在的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM