Created
March 1, 2011 14:37
-
-
Save kolo/849211 to your computer and use it in GitHub Desktop.
MessageSenderObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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