ActionMailerに添付ファイルとしてprawn pdfをレンダリングするには?私はdelayed_jobを使用して理解していない、どうすればアクションメーラー(コントローラーではない)でpdfファイルをレンダリングできますか?私はどんなフォーマットを使うべきですか?Rails 3レンダリングPrawn pdf in ActionMailer
7
A
答えて
7
あなたは、Prawnに文字列にPDFをレンダリングし、それを電子メールの添付ファイルとして追加する必要があります。添付ファイルの詳細については、ActionMailer docsを参照してください。ここで
は例です:
class ReportPdf
def initialize(report)
@report = report
end
def render
doc = Prawn::Document.new
# Draw some stuff...
doc.draw_text @report.title, :at => [100, 100], :size => 32
# Return the PDF, rendered to a string
doc.render
end
end
class MyPdfMailer < ActionMailer::Base
def report(report_id, recipient_email)
report = Report.find(report_id)
report_pdf_view = ReportPdf.new(report)
report_pdf_content = report_pdf_view.render()
attachments['report.pdf'] = {
mime_type: 'application/pdf',
content: report_pdf_content
}
mail(:to => recipient_email, :subject => "Your report is attached")
end
end
0
私のソリューション:私はメール機能のためのブロックを書いていないとマルチパートメールが誤っていたので、
render_to_string('invoices/show.pdf', :type => :prawn)
PDFが破損していました。
3
PRAWNのRailsCastに従った。既に何が言われているのか、同様に達成しようとしていたことを考えて、私は添付ファイル名を設定してPDFを作成しました。
InvoiceMailer:
def invoice_email(invoice)
@invoice = invoice
@user = @invoice.user
attachments["#{@invoice.id}.pdf"] = InvoicePdf.new(@invoice, view_context).render
mail(:to => @invoice.user.email,
:subject => "Invoice # #{@invoice.id}")
end
関連する問題
- 1. WYSIWYG HTMLエディタ - > PDF(Prawn + Rails)
- 2. ActionMailer 3 Railsなし
- 3. Ruby on Rails用Prawn PDFを使用してPDFをブラウザにレンダリングできない
- 4. PrawnでイメージにJSONをレンダリングするPDF
- 5. Rails、Prawn - PDFはブラウザなどに表示
- 6. 未定義のメソッドprawn-railsで `pdf`
- 7. Rails 3 ActionMailerモデル属性
- 8. レンダリングpdf in chrome in iframe
- 9. PDFレンダリングGibberish in Browser
- 10. 画像を含むPDFを生成するPrawn PDF Rails
- 11. prawn error reading generated pdf
- 12. jQuery in Rails 3 "Beginning Rails 3"
- 13. Rails 3 ActionMailerローカライズされたビューフォールバック
- 14. Prawn PDFとAction Mailerが添付されていないPDF
- 15. ActionMailer :: BaseレンダリングテキストビューRails 4.0
- 16. POST in rails 3
- 17. Mollom in Rails 3
- 18. Has_and_belongs_to_many in Rails 3
- 19. PrawnはHeroku上でPDFをレンダリングしませんが、ローカルにします
- 20. Prawn PDFのバウンディングボックスへのフィット
- 21. Prawn PDFテーブルの混合フォーマット
- 22. PDF Prawn:テキストオーバーライドの問題
- 23. Rails PDFからPrawnの代替手段を生成
- 24. RailsアプリケーションのアップデートでPrawn PDFレポートを作成する前に
- 25. Ruby on Railsの計算結果+ Prawn PDF Generator
- 26. Railsレンダリングjson partial in model
- 27. Prawn for Rails 4のインストール方法
- 28. Rails 3 - request.request_uri in model
- 29. Rails ActionMailerを使用した電子メールのQRコードのレンダリング
- 30. PrawnとPDFKitのRailsアプリ、Prawnはもはや動作しません
私はすでにビュー/請求書/ show.pdf.prawnを持っています。 InvoicesControllerはそれを正常にレンダリングします。メーラーでrender_to_stringを使ってレンダリングしようとしましたが、壊れたPDFがありました。この既存のビューファイルをレンダリングする方法は? render_to_stringの型または書式を指定する必要があります。 – maxs