0

我正在尝试将邮件程序集成到我的应用程序中。下新订单时,我需要发送一封交易电子邮件。将收件人传递给邮件程序时,我一直遇到无方法错误。当我明确定义收件人时,这很好用,但我需要将收件人变量从我的模型传递给消息,以获得我想要的行为。任何帮助调试将不胜感激,因为我似乎无法追查我的错误。

错误输出:

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>
4

1 回答 1

0

我相信您的 Controller 操作中有错字。

你应该替换@beds@bed

于 2015-12-09T02:18:46.310 回答