How to create notification system in rails? -
basically, want create notification facebook , stackoverflow. specifically, in post-comments system, when post commented, involved (people creates post , create comments, except new commenter) gets notification message post commented. , notification dismissed when people have read it.
i have tried use mailboxer gem implement it, saddly there no example available using related methods, including social_stream itself.
is there other way create notification system?
and when try create scratch several problems:
model notification topic_id: integer user_id: integer checked: boolean #so can tell whether notification read or not
- dismissing notication after being read users
i think need turn every notification messages' "checked" attribute true after user visit index of notification.(in notificationscontroller)
def index @notifications=current_user.notication.all @notification.each |notification| notification.checked = true end @notification.save! end
2.selecting users notify(and exclude user making new comment)
i have no idea in wrting queries....
3.creating notifications
i think should like
#in commentcontroller def create #after creating comments, creat notifications @users.each |user| notification.create(topic_id:@topic, user_id: user.id) end end
but think ugly
there no need anwer 3 problems above, simple solution notification system preferable , thanks....
i think on right path.
a better notifications#index
def index @notifications = current_user.notications @notifications.update_all checked: true end
notify users
user.uniq.joins(:comments).where(comments: {id: @comment.post.comment_ids}).reject {|user| user == current_user }
unique users participated in @comment's post comments, reject (remove result) current_user.
- an observer pointed out joão daniel, preferred on after_create. "rails best practice" describes pretty well: http://rails-bestpractices.com/posts/2010/07/24/use-observer
Comments
Post a Comment