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:
Whenever an event happens, find all users who prefer instant event email notifications and send it to them immediately.
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.
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.
精彩评论