Skip to content

Instantly share code, notes, and snippets.

@dhh
Created May 11, 2011 14:43
Show Gist options
  • Save dhh/966575 to your computer and use it in GitHub Desktop.
Save dhh/966575 to your computer and use it in GitHub Desktop.
Mailbag feature
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