I am trying to send the pdf
as an attachment
in the email. but getting an error.
ctionView::MissingTemplate at /invoises/BRUqWOeEVNSN6GCwxQqLGg%253D%253D/send_invoice_email
Missing template invoises/#{invoise.id}/show_pdf_invoice.pdf.erb with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :m
i am using wicked_pdf
gem.trying to generate the pdf
from html
view
method in controller
def send_invoice_email
CompanyMailer.invoice(@invoise.id).deliver
redirect_to invoices_path, notice: 'Invoice Sent successfully.'
end
logic in mailer
:
def invoice(invoice)
invoice = Invoice.find(invoice)
attachments["invoice.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "invoice",:template => 'invoices/#{invoice.id}/show_pdf_invoice.pdf.erb')
)
mail(to: "[email protected]", subject: 'Your todo PDF is attached')
end
method in controller
def show_pdf_invoice
respond_to do |format|
format.html { render :layout => false }
format.pdf do
render pdf: "show_pdf_invoice"
#render :pdf => "pdf"#, :layout => 'pdf.html.erb'
end
end
end
and in invoices/show_pdf_invoice.pdf.erb
<h1>this is pdf invoice.<h1>
and in company_mailer/invoice.html.erb
please find attached pdf.
Issue is fixed. i need not to pass id in the url. i need to pass only
render_to_string(template: 'invoices/show_pdf_invoice.pdf.erb')