レールで通知を作成する方法を示す決定的な記事が見つかりません。誰もが良い解決策であるかのように Mailboxer について話しているようですが、:Notify メソッドに関する 1 つの段落以外は、非常に漠然としています。
そのため、アクティビティ (Public Activity Gem) に属する通知モデルを作成し、アクティビティ モデルで after_create コールバックを使用して通知メソッドを呼び出し、その通知メソッドが問題のアクティビティ オブジェクトの通知メソッドを呼び出すことを考えています。
図として
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
注: すべてをモデルで処理したほうがよいと思うので、すべてをコントローラーから遠ざけるように最善を尽くしています。しかし、私は提案を受け入れます
ありがとう