我正在尝试使用ActionMailer创建电子邮件。 发票电子邮件已发送。
但是,在发送电子邮件后,我在屏幕上收到此错误:
ActionView::MissingTemplate at /invoices/sendinvoice
Missing template invoices/sendinvoice, application/sendinvoice
这是我的invoices_controller.rb
def sendinvoice
@invoice = Invoice.find(params[:invoice_id])
InvoiceMailer.invoice_email(@invoice).deliver
end
这是在mailers / 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 => "New Invoice from " + @invoice.tenant.name )
end
end
这是在views / invoice_email.html.erb
中<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<body>
<h2>Invoice</h2>
</body>
</html>
这是发票/ show.html.erb
中的按钮<%= link_to 'Send Invoice', invoices_sendinvoice_path(:invoice_id => @invoice), :class => 'btn btn-primary' %>
这是在路线:
get "invoices/sendinvoice"
感谢您的帮助!
答案 0 :(得分:1)
是的,您必须在发送电子邮件时指定一个视图。您的操作没有视图,并且rails要求这样做。该视图应位于app / views / invoices / sendinvoice.html.erb
中