Created
July 11, 2011 14:25
-
-
Save betamatt/1075951 to your computer and use it in GitHub Desktop.
Delay Rails 2.x mailers
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
# 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