forked from tower-archive/tower
-
Notifications
You must be signed in to change notification settings - Fork 0
mailers
Lance Pollard edited this page Apr 12, 2012
·
1 revision
class Notifier extends Tower.Mailer
@welcome: (user) ->
@notification("welcome", name: user.firstName)
@notification: (key, locals = {}) ->
Notifier.defaultUrlOptions.host = locals.host || "mysite.com"
subject = Tower.t("emails.#{key}.subject", locals)
from = locals.from || I18n.t("emails.from")
to = locals.to
@mail from: from, to: to, subject: subject
Then you use it like this:
class User extends Tower.Model
welcome: ->
Notifier.notification(@).deliver()
Here's a pattern I use a lot
class User extends Tower.Model
@welcome: (id) ->
Notifier.notification(@constructor.find(id)).deliver()
welcome: ->
@constructor.async("welcome", @id)