Skip to content

Instantly share code, notes, and snippets.

@roovo
Created June 1, 2009 12:04
Show Gist options
  • Save roovo/121364 to your computer and use it in GitHub Desktop.
Save roovo/121364 to your computer and use it in GitHub Desktop.
module Merb
class MailController
def dispatch_and_deliver(method, mail_params)
non_array = mail_params.dup.delete_if { |k,v| v.is_a?(Array) }
array = mail_params.dup.delete_if { |k,v| !v.is_a?(Array) }
@mailer = self.class._mailer_klass.new(non_array)
@mail = @mailer.mail
@method = method
array.each do |k, values|
values.each { |value| @mail.add_header(k.to_s, value) }
end
# dispatch and render use params[:action], so set it
self.action_name = method
body = _dispatch method
if !@mail.html.blank? || !@mail.text.blank?
@mailer.deliver!
Merb.logger.info "#{method} sent to #{@mail.to} about #{@mail.subject}"
else
Merb.logger.info "#{method} was not sent because nothing was rendered for it"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment