-
Notifications
You must be signed in to change notification settings - Fork 120
mailers
Lance Pollard edited this page Sep 25, 2012
·
4 revisions
class App.Notifier extends Tower.Mailer
@welcome: (user) ->
@notification("welcome", name: user.firstName)
@notification: (key, locals = {}) ->
App.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 App.User extends Tower.Model
welcome: ->
App.Notifier.notification(@).deliver()
Here's a pattern I use a lot
class App.User extends Tower.Model
@welcome: (id) ->
App.Notifier.notification(@constructor.find(id)).deliver()
welcome: ->
@enqueue("welcome", @id)