我正在尝试将一些逻辑放入我的邮件中。基本上,我的一个模型中有十几个布尔字段,对于每个为真的字段,我希望将电子邮件发送到特定地址。具有布尔字段的模型称为 Ecn。这是我的通知文件:
class EcnNotifier < ActionMailer::Base
default from: "engineering_notices@wilfley.com"
def submitted(ecn)
@ecn = ecn
@email_list = EmailList.all
if @ecn.distribute_engineering?
mail to: "abc@gmail.com", subject: 'ECN approvald'
else
end
if @ecn.distribute_purchasing?
mail to: "123@gmail.com", subject: 'ECN approval'
else
end
mail to: "aaa@test.com", subject: 'ECN approval'
end
end
我在控制器中创建的操作如下所示:
def submit
@ecn = Ecn.find(params[:id])
respond_to do |format|
EcnNotifier.submitted(@ecn).deliver
format.html { redirect_to ecns_url, alert: "Ecn has been submitted for approval." }
format.json { render json: @ecns }
end
end
一封电子邮件会自动发送到 aaa@test.com,但无论distribute_engineering 和distribute_purchasing 是否为真,都不会向其他地址发送电子邮件。我假设我错误地访问了我的对象实例,但我不确定我哪里出错了。