0

我正在尝试使用 ActionMailer 发送电子邮件。

这是 invoice_mailer.rb

class InvoiceMailer < ActionMailer::Base
  default from: "ndeavor@ameipro.com"
  def invoice_email(invoice)
    @invoice = invoice
    mail(:to => @invoice.workorder.contact.email, :subject => "nDeavor New Invoice")
  end
end

这是控制器代码:

  def sendinvoice
    @invoice = params[:invoice_id]
    InvoiceMailer.invoice_email(@invoice).deliver
  end

这是视图代码:

<%= link_to 'Send Invoice', invoices_sendinvoice_path(:invoice_id => @invoice), :class => 'btn btn-primary' %>

我得到的错误来自 invoice_mailer 中的这一行:

mail(:to => @invoice.workorder.contact.email, :subject => "nDeavor New Invoice")

这是错误:

undefined method `workorder' for "10":String

谢谢您的帮助!

4

1 回答 1

0

在您的sendinvoice方法中,您有@invoice = params[:invoice_id]10 分配给@invoice然后将其传递给InvoiceMailer.invoice_email.

你可能想要的是@invoice = Invoice.find(params[:invoice_id]). 这将为您获取 ID 为 10 的 Invoice 对象。

于 2013-10-05T00:40:53.560 回答