Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f185e5070c
Fetching contributors…

Cannot retrieve contributors at this time

25 lines (20 sloc) 0.665 kb
class NotifierObserver < ActiveRecord::Observer
observe :comment, :answer
def after_create(model)
notify(model)
end
def before_destroy(model)
destroy(model)
end
private
def notify(model)
if model.is_a?(Comment) && model.commentable.user != model.user
model.commentable.user.notifications.create(:notifierable => model)
elsif model.is_a?(Answer) && model.question.user != model.user
model.question.user.notifications.create(:notifierable => model)
end
end
def destroy(model)
Notification.where(:notifierable_id => model.id, :notifierable_type => model.class.to_s).first.destroy
end
end
Jump to Line
Something went wrong with that request. Please try again.