Ruby on rails 轨道4.1->;4.2已导致发送电子邮件的创建后回调停止工作
在我的Ruby on rails 轨道4.1->;4.2已导致发送电子邮件的创建后回调停止工作,ruby-on-rails,Ruby On Rails,在我的Note模型(Note.rb)中,下面的代码段由活动记录回调触发: 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 在N
Note
模型(Note.rb
)中,下面的代码段由活动记录回调触发:
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语句根据多态note\u类型发送不同的电子邮件模板。下面是这个片段:
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
def运行(类型,注释)
@注=注
案例类型
什么时候“申请”
app=Application.find(@note.id)
app.users.each do|用户|
如果user.id!=@note.user.id&&user.email
邮件(发送至:user.email,
发件人:@note.user.name+“”,
主题:“我的秘密主题”,
模板名称:“application.html.erb”)。立即交付
结束
结束
什么时候‘预约’
a=约会。查找(@note.note\u id)
a、 用户。每个do |用户|
如果user.id!=@note.user.id&&user.email
邮件(发送至:user.email,
发件人:note.user.name+“”,
主题:“我的秘密主题”,
模板名称:“appointment.html.erb”)。立即交付
结束
结束
结束
结束
由于从Rails 4.1升级到Rails 4.2,电子邮件不再像以前那样发送
是什么导致了这个问题?我确实更改了邮件(..)。将发送到邮件(..)。立即发送
我尝试添加将“test”
放在run方法的顶部,但它不会将字符串放在控制台上。没有抛出任何错误问题是从未调用run
。您需要立即呼叫deliver\u
在适当的位置
试试这个:
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
而不是在你的邮件中调用deliver\u
看