Rails 应用程序中电子邮件频率配置的策略

发布于 2024-11-14 21:53:00 字数 122 浏览 2 评论 0原文

我期待着允许我的用户配置他们的电子邮件通知频率。

我想为他们提供典型的选项:直接电子邮件、每日和每周摘要

¿在 Rails 3 应用程序中构建此应用程序的最佳策略是什么?

谢谢大家!

I'm looking forward to allowing my users configure their email notifications frequency.

I'd like to offer them the typical options: direct email, daily and weekly digests

¿What would it be the best strategy to build this within a rails 3 application?

Thanks all !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被你宠の有点坏 2024-11-21 21:53:00

您可以在 users 表上有一个 email_Frequency_preference 字符串列来存储他们的首选项。然后,您可以通过电子邮件频率首选项找到用户:

User.find_all_by_email_frequency_preference    # :instantly | :weekly | :monthly

我还建议使用 Event 模型,其中包含名称和描述,以表示您想要通知用户的可能发生的事件。然后,您可以按创建日期查找事件:

Event.find :created_at => start_date..Date.today

现在,您必须分别处理所有三个频率首选项:

  1. 每当事件发生时,找到所有喜欢即时事件电子邮件通知的用户并立即将其发送给他们。

  2. 在每周结束时,查找该周发生的所有事件:

    start_date = Date.today.beginning_of_week
    

    将他们的描述合并到一封电子邮件中,然后找到所有喜欢每周事件电子邮件通知的用户并将其发送给他们。

  3. 在每个月底,查找该月发生的所有事件:

    start_date = Date.today.beginning_of_month
    

    将他们的描述合并到一封电子邮件中,然后找到所有喜欢每月事件电子邮件通知的用户并将其发送给他们。

You could have an email_frequency_preference string column on your users table that stores their preference. Then you can find users by their email frequency preference:

User.find_all_by_email_frequency_preference    # :instantly | :weekly | :monthly

I also suggest having an Event model, with name and description, to represent events that may happen that you want to notify your users of. Then you can find events by their creation date:

Event.find :created_at => start_date..Date.today

Now, you have to handle all three frequency preferences separately:

  1. Whenever an event happens, find all users who prefer instant event email notifications and send it to them immediately.

  2. At the end of every week, find all events that happened that week:

    start_date = Date.today.beginning_of_week
    

    Combine their descriptions into a single email, then find all users who prefer weekly event email notifications and send it to them.

  3. At the end of every month, find all events that during happened that month:

    start_date = Date.today.beginning_of_month
    

    Combine their descriptions into a single email, then find all users who prefer monthly event email notifications and send it to them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文