我正在尝试将邮件程序集成到我的应用程序中。我需要在下新订单时发送交易电子邮件。将收件人传递给邮件程序时,我一直遇到no方法错误。这在我明确定义收件人时工作正常,但是我需要将收件人变量从我的模型传递给消息以获得我想要的行为。任何帮助调试都将非常感激,因为我似乎无法追查我的错误。
错误输出:
NoMethodError (undefined method `recipient' for nil:NilClass):
app/mailers/bed_mailer.rb:8:in `bed_email
邮件程序:
class BedMailer < ApplicationMailer
default :from => 'info@paperlesspcs.com'
def bed_email(bed)
@bed = bed
mail(
:subject => 'Critical Documentation Needed' ,
:to => @bed.recipient ,
:track_opens => 'true',
:body => 'something'
)
end
end
相关控制器操作:
def create
@bed = current_supplier.beds.build(bed_params)
respond_to do |format|
if @bed.save
BedMailer.bed_email(@beds).deliver_later
format.html { redirect_to @bed, notice: 'Bed was successfully created.' }
format.json { render :show, status: :created, location: @bed }
else
format.html { render :new }
format.json { render json: @bed.errors, status: :unprocessable_entity }
end
end
修改/更新
我更正了下面评论中提到的拼写错误,但是当我删除:body
行以转发到我的首选邮件程序布局Missing template bed_mailer/bed_email with "mailer". Searched in: * "bed_mailer"
我的预期布局:
bed_mailer.html.erb
<h2> Critical Documentation Needed: </h2>
<p> In order to quickly process your referral for <strong> <%= @bed.patient_name %> </strong>, we need additional documentation.
<br>
For your convience, please follow this link to electronically complete the documentation process: </p>
<br>
<h4> <%= link_to 'Click Here to complete the necessary documents', edit_bed_url(:id => @bed.id, :token => @bed.token) %> </h4>
<br>
答案 0 :(得分:0)
我相信您的控制器操作中存在拼写错误。
您应该将@beds
替换为@bed