2
我無法找到任何確鑿的文章,顯示如何在rails中創建通知。每個人似乎都在談論Mailboxer,因爲這是一個很好的解決方案,但除了它們的一個段落:Notify方法外,它似乎很模糊。我在Rails中創建通知系統
因此,我正在考慮創建一個屬於Activity(公共活動Gem)的通知模型,然後在活動模型上使用after_create回調來調用notify方法,然後調用所討論活動對象的notify方法。
作爲圖
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
所以當註釋模式被調用時,公共活動跟蹤它,然後調用回的意見通知方法的通知模式來拯救
通知模型只會包括
user_id, activity_id, read:boolean
注:我想我最好把一切都出了控制器的,因爲我認爲,整個事情就在模型中更好地處理。但我願意接受建議
感謝