rails 3: how to abort delivery method in actionmailer? -


in mailer controller, under conditions (missing data) abort sending email.

how exit controller method without still rendering view in case?

return if @some_email_data.nil?

doesn't trick since view still rendered (throwing error every place try use @some_email_data unless add lot of nil checks)

and if nil checks, complains there's no 'sender' (because supposed did 'return' before getting line set sender , subject.

neither render ... return

basically, return doesn't return inside mailer method!

i encountered same thing here.

my solution following:

module bulletproofmailer   class blackholemailmessage < mail::message     def self.deliver       false     end   end    class abortdeliveryerror < standarderror   end    class base < actionmailer::base      def abort_delivery       raise abortdeliveryerror     end      def process(*args)       begin         super *args       rescue abortdeliveryerror         self.message = bulletproofmailer::blackholemailmessage       end     end   end end 

using these wrapper mailer this:

class eventmailer < bulletproofmailer::base   include resque::mailer   def event_created(event_id)     begin       @event = calendarevent.find(event_id)     rescue activerecord::recordnotfound       abort_delivery     end   end end 

it posted in blog.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -