Skip to content

Instantly share code, notes, and snippets.

@harlow
Forked from dhh/gist:966575
Created August 6, 2014 00:10
Show Gist options
  • Save harlow/bfe3820adca57f7c1808 to your computer and use it in GitHub Desktop.
Save harlow/bfe3820adca57f7c1808 to your computer and use it in GitHub Desktop.
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