【发布时间】:2015-06-03 16:42:30
【问题描述】:
在我的 Note 模型 (note.rb) 中,下面的 sn-p 由 Active Record 回调触发:
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
在NoteMailer 中,我有另一个switch 语句来发送基于多态notable_type 的不同电子邮件模板。这是sn-p:
def run(type, note)
@note = note
case type
when 'application'
app = Application.find(@note.notable_id)
app.users.each do |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'
a = Appointment.find(@note.notable_id)
a.users.each do |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
自从从 Rails 4.1 升级到 Rails 4.2 后,电子邮件不再像以前那样发送出去了。
什么可能导致这个问题?我确实将mail(..).deliver 更改为mail(..).deliver_now。
我尝试在顶部的 run 方法中添加puts "test",但它并没有将字符串放入控制台。根本不会抛出任何错误
【问题讨论】:
标签: ruby-on-rails