Skip to content

Instantly share code, notes, and snippets.

@betamatt
Created July 11, 2011 14:25
Show Gist options
  • Save betamatt/1075951 to your computer and use it in GitHub Desktop.
Save betamatt/1075951 to your computer and use it in GitHub Desktop.
Delay Rails 2.x mailers
# Handle mail delivery in the background. Only the minimum amount of data should go in the job not
# the fully rendered email content.
# I haven't tested this but some variant should work.
ActionMailer::Base.class_eval do
def self.create_and_deliver!(message, *parameters)
new(message, *parameters).deliver!
end
def method_missing_with_delay(method_symbol, *parameters)#:nodoc:
case method_symbol.id2name
when /^deliver_([_a-z]\w*)/ then self.class.create_and_deliver!($1, *parameters)
else method_missing_without_delay(method_symbol, *parameters)
end
end
alias_method_chain :missing_method, :delay
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment