Skip to content

Instantly share code, notes, and snippets.

@kolo
Created March 1, 2011 14:37
Show Gist options
  • Save kolo/849211 to your computer and use it in GitHub Desktop.
Save kolo/849211 to your computer and use it in GitHub Desktop.
MessageSenderObserver
class MessageSenderObserver < ActiveRecord::Observer
observe :attendee
def after_create(model)
model.user.post_message(:all, I18n::t("messages.#{model.class.name.underscore}.create",
:title => title_for(model),
:link => link_for(model)))
end
private
include Rails.application.routes.url_helpers
def link_for(model)
url = "#"
case model.class.name
when "Attendee"
url = event_path(model.event)
end
Settings.application.hostname + url
end
def title_for(model)
case model.class.name
when "Attendee"
model.event.subject
else
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment