I can't find any conclusive articles showing how to create notifications in rails. Everyone seems to talk about Mailboxer like it's a good solution, but other than the one paragraph they have on the :Notify method, it seems very vague.
So I'm thinking of creating a notification model which belongs to Activity (Public Activity Gem) and then using an after_create callback on the activity model to call a notify method which then calls the notify method of the activities object in question.
As a diagram
class Comment
include PublicActivity::Model
tracked
def notify
#Loop through all involved users of this modal instance and create a Notify record pointing to the public activity
end
end
class Activity < PublicActivity::Activity # (I presume I can override the gems Activity model in my App?)
after_create :notify
private
def notify
#Call the notify function from the model referenced in the activity, in this case, comment
end
end
So when the comment modal is called, public activity tracks it which then calls back the comments notify method to save in a Notify model
Notify model would simply consist of
user_id, activity_id, read:boolean
Note: I am trying my best to keep everything out of the controller, as I think the whole thing would be better handled in the model. But I'm open to suggestions
Thanks