我正在尝试在邮件中添加一些逻辑。基本上,我的一个模型中有十二个布尔字段,对于每个正确的字段,我希望将电子邮件发送到特定地址。具有布尔字段的模型称为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是否为真,都不会将电子邮件发送到其他地址。我以为我错误地访问了我的对象实例,但是我不确定我要去哪里。