Created
May 11, 2011 14:43
-
-
Save dhh/966575 to your computer and use it in GitHub Desktop.
Mailbag feature
This file contains 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 NotesController < ApplicationController | |
def create | |
@note = @project.notes.create params[:note].merge( | |
creator: current_user, subscribers: extract_subscribers(params[:note])) | |
@note.subscribers.each { |subscriber| Subscriptions.note(@note, subscriber).deliver } | |
end | |
end | |
class Subscriptions < ActionMailer::Base | |
def note(note, recipient) | |
@note = note | |
mail to: recipient.email_address, subject: note.title | |
end | |
end | |
# To this instead | |
class NotesController < ApplicationController | |
def create | |
@note = @project.notes.create params[:note].merge( | |
creator: current_user, subscribers: extract_subscribers(params[:note])) | |
# Returns an a Mailbag of mail objects, that responds to deliver | |
Subscriptions.to(@note.subscribers.collect(&:email_address)).note(@note).deliver | |
end | |
end | |
class Subscriptions < ActionMailer::Base | |
def note(note) | |
@note = note | |
mail subject: note.title | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment