0
if params[:invoice_id].presence
  @invoice = Invoice.find(params[:invoice_id])
  attachments['invoice.pdf'] = WickedPdf.new.pdf_from_string(
    render_to_string(
      template: 'invoices/service',
      locals: { current_user: }
    )
  )
end

I have attached a PDF from wickedpdf but after sending the attachment it comes as blank white page.

I am trying to send Attachment in Ruby on Rails with ActionMailer with PDF as an attachment.

anothermh
  • 9,815
  • 3
  • 33
  • 52

1 Answers1

0

By looking at the example in the Wicked PDF documentation it looks like you are missing the layout option in the render_to_string method.

I suggest to do something like this:

if params[:invoice_id].presence
  @invoice = Invoice.find(params[:invoice_id])
  attachments['invoice.pdf'] = WickedPdf.new.pdf_from_string(
    render_to_string(
      template: 'invoices/service',
      locals: { current_user: },
      # add this line and change the value with the right pdf layout path
      layout: 'layouts/pdf' 
    )
  )
end
caiobm4
  • 235
  • 1
  • 7