Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: Strategy for system notifications

This is a common pattern among apps and I am sure has a graceful solution, but for the life of me I can't find an answer. A big issue is I don't quite know what to call it!

I am trying to find the proper solution to give one-time notifications to every user of a system. When that user acknowledges or closes the notification, they do not see it again personally, but others users will until they acknowledge it.

This is common when doing maintenance notices, new features, on-boarding, etc.

Obviously, this would need to live in some database as a flag that this particular has acknowledged this particular message, but it seems like that could become heavy and unwieldy quickly without a well-thought out plan for delivering these.

like image 428
John R Avatar asked Nov 04 '22 06:11

John R


1 Answers

See my answer to a similar question.

Messages live in my user model as a serialized array. This way I can use simple array methods such as #push for new messages. Users only deal with messages specific to them, using #delete_at to cancel individual messages, or #clear to cancel them all.

For broadcast notifications, you could do something as obnoxious as:

User.all.map {|x| x.messages.push "You have been notified." ; x.save }

which, if used infrequently, isn't that big of a deal.

like image 155
Substantial Avatar answered Nov 18 '22 04:11

Substantial