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 !

Paul R
  • 208,748
  • 37
  • 389
  • 560
dgilperez
  • 10,716
  • 8
  • 68
  • 96

1 Answers1

5

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.

Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107