Rupesh Jayaprakash
2014-Jul-16 10:03 UTC
Alias mail method in class Mailer < ActionMailer::Base
Hello, I have a class in the core application, -------------------------------------------------- class Mailer < ActionMailer::Base . . def mail(headers={}, &block) headers.merge! 'Auto-Submitted' => 'auto-generated', 'From' => Setting.mail_from, 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" . . m end end -------------------------------------------------- I need to patch this class, (As a plugin), So that the 'From' is configurable. Here is the plugin patch I tried and failed to get the expected result. -------------------------------------------------- module Patches module MailerPatch def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do unloadable alias_method_chain :mail, :patch end end end module InstanceMethods def mail_with_patch(headers={}, &block) m = mail_without_patch(headers, &block) m.from = User.current m end end end Mailer.send(:include, Patches::MailerPatch) -------------------------------------------------- Am I doing something wrong here, Please help me. Thank You. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1764506d4795ee49528805dccf2a4acf%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.