Reputation: 5953
I'm trying to create an email using ActionMailer. The invoice email gets sent.
But, I'm getting this error on the screen after the emails is sent:
ActionView::MissingTemplate at /invoices/sendinvoice
Missing template invoices/sendinvoice, application/sendinvoice
This is in my invoices_controller.rb
def sendinvoice
@invoice = Invoice.find(params[:invoice_id])
InvoiceMailer.invoice_email(@invoice).deliver
end
This is in 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
This is in 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>
This is a button in the invoices/show.html.erb
<%= link_to 'Send Invoice', invoices_sendinvoice_path(:invoice_id => @invoice), :class => 'btn btn-primary' %>
This is in routes:
get "invoices/sendinvoice"
Thanks for the help!
Upvotes: 2
Views: 2202
Reputation: 5111
Yes, you have to specify one view when the email is sent. Your action does not have a view and rails is asking for that. The view should be in app/views/invoices/sendinvoice.html.erb
Upvotes: 1