Rails 4.1 -> 4.2 has caused an after_create callback that sends an e-mail to stop working -
in note
model (note.rb
) have snippet below being triggered active record callback:
def creation_email case self.notable_type when 'application' notemailer.run('application', self) when 'appointment' notemailer.run('appointment', self) end self.inbounded = 1 self.save end
in notemailer
have switch statement send different e-mail templates based on polymorphic notable_type
. here snippet:
def run(type, note) @note = note case type when 'application' app = application.find(@note.notable_id) app.users.each |user| if user.id != @note.user.id && user.email mail(to: user.email, from: @note.user.name + " <application." + app.id.to_s + "." + user.id.to_s + "@mail.mysecretdomain.com>", subject: "my secret subject", template_name: "application.html.erb").deliver_now end end when 'appointment' = appointment.find(@note.notable_id) a.users.each |user| if user.id != @note.user.id && user.email mail(to: user.email, from: note.user.name + " <appointment." + a.id.to_s + "." + user.id.to_s + "@mail.mysecretdomain.com>", subject: "my secret subject", template_name: "appointment.html.erb").deliver_now end end end end
since upgrading rails 4.2 rails 4.1, e-mails not sending out used to.
what causing problem? did change mail(..).deliver
mail(..).deliver_now
.
i've tried adding puts "test"
in run method @ top, , not put string console. no errors @ thrown
the problem run
never called. need call deliver_now
in proper place.
try :
def creation_email case self.notable_type when 'application' notemailer.run('application', self).deliver_now when 'appointment' notemailer.run('appointment', self).deliver_now end self.inbounded = 1 self.save end
instead of calling deliver_now
in mailer.
see http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2
Comments
Post a Comment