/ Published in: Ruby
Sick of writing almost the same thing over and over in your ActionMailer classes? Skip all that, and use something like this.
(If you have a configuration loaded into a constant, you could just replace the defaults above and use your app's defaults to make it all cleaner, of course)
And then from your controller you can do stuff like this:
Expand |
Embed | Plain Text
class Mailer < ActionMailer::Base helper ActionView::Helpers::UrlHelper def generic_mailer(options) @cc = options[:cc] || "" @bcc = options[:bcc] || "" @subject = options[:subject] || "" @body = options[:body] || {} @headers = options[:headers] || {} @charset = options[:charset] || "utf-8" end # Create placeholders for whichever e-mails you need to deal with. # Override mail elements where necessary def contact_us(options) self.generic_mailer(options) end ... end Mailer.deliver_contact_us( :body => { :name => params[:name], :phone => params[:phone], :email => params[:email], :message => params[:message] }, )
You need to login to post a comment.
