Created
June 1, 2009 12:04
-
-
Save roovo/121364 to your computer and use it in GitHub Desktop.
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
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