我正在尝试使用 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
谢谢您的帮助!