开发者

Strategies for email frequency configuration in a rails app

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

I'd like to offer them the typical o开发者_如何学JAVAptions: direct email, daily and weekly digests

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

Thanks all !


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜