2016-12-16 13 views
1

pdfattachmentとして電子メールに送信しようとしています。エラーが表示されます。wicked-pdfから生成された電子メールにpdf添付ファイルを送信できません。

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

私はmailercontroller

def send_invoice_email 
    CompanyMailer.invoice(@invoise.id).deliver 
    redirect_to invoices_path, notice: 'Invoice Sent successfully.' 
    end 

ロジックでpdf

view htmlからメソッドを生成するために wicked_pdf gem.tryingを使用しています:

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 

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 

方法及びinvoices/show_pdf_invoice.pdf.erb

<h1>this is pdf invoice.<h1> 

およびcompany_mailer/invoice.html.erb

please find attached pdf. 
+0

invoice /#{invoice.id} /show_pdf_invoice.pdf.erb "に変更すると、文字列補間の最も外側の引用符として二重引用符が使用されます。 – jvnill

+0

私はその行を変更しました。それでも同じエラーです。 – John

+1

'render_to_string(テンプレート: '請求書/ show_pdf_invoice.pdf.erb')に変更 – jvnill

答えて

0

号には固定されています。私はURLのIDを渡す必要はありません。私は `render_to_string`の仕組みにあまり慣れていませんが、あなたの文字列の補間が正しく設定されていないように見えます。render_to_string(template: 'invoices/show_pdf_invoice.pdf.erb')

関連する問題