0
我想使用ActionMailer發送電子郵件。Rails的ActionMailer參數是一個字符串
這是invoice_mailer.rb
class InvoiceMailer < ActionMailer::Base
default from: "[email protected]"
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
感謝您的幫助!
感謝您的回答! – Reddirt