ActionMailer에서 새우 pdf를 첨부 파일로 렌더링하는 방법은 무엇입니까? 내가 delayed_job을 사용하고 이해하지 못한다면 어떻게 pdf 파일을 액션 메일러 (컨트롤러가 아닌)에서 렌더링 할 수 있을까요? 어떤 형식을 사용해야합니까?Rails 3 렌더링 새우 pdf 파일 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
내 솔루션 : I 메일 기능과 여러 부분 이메일 블록을 쓰기 정확하지 않았기 때문에
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. ActionMailer 3 with Rails
- 2. 새우 PDF 표 혼합 형식
- 3. 인쇄 새우 생성 pdf
- 4. Rails 3 렌더링 액션
- 5. Rails 3 - 렌더링 후 JS 렌더링 JSON
- 6. 새우 pdf 및 페이지 나누기
- 7. 새우 루비 문서 생성 pdf
- 8. 새우 PDF : 중첩 테이블을 생성해야합니다.
- 9. Rails 3 렌더링 iframe raw()
- 10. PDF Writer for Rails 3
- 11. Rails ActionMailer, link_to forward?
- 12. actionmailer/gmail/rails 2.3.2
- 13. Mac에서 Rails ActionMailer 문제
- 14. Rails 3 "ActionMailer :: Base에서 '메서드'를 찾을 수 없습니다."
- 15. 새우 PDF 및 빈 데이터베이스 셀?
- 16. Rails 3 -보기에서 PDF보기 및 이메일에 첨부하기
- 17. Rails 3 - 세분화 오류를 일으키는 Devise/ActionMailer/RUBY-SMTP
- 18. 레일스 3 : ActionMailer
- 19. 레일 새우
- 20. Rails 3 파일 다운로드 마법사
- 21. Rails 3.2 ActionMailer 데모 실패
- 22. 새우 보석
- 23. 새우 - 테이블 - 아스키 코드 - Pdf 생성
- 24. 새우 PDF : 기본 페이지가없는 템플릿을 만듭니다.
- 25. 새우 PDF 파일을 Amazon S3에 저장하는 방법
- 26. Rails 3 렌더링 JS가 아무 것도하지 않음
- 27. Rails 3 - HTML 이후 JS 렌더링 방법
- 28. ruby on rails 3, 하나의보기에서 여러보기를 렌더링
- 29. Rails 3 mailer issue
- 30. iOS 4.3 PDF 파일 렌더링 문제
이미 뷰/송장/show.pdf.prawn 있습니다. InvoicesController가 성공적으로 렌더링합니다. 메일러에서 render_to_string을 사용하여 렌더링하려했는데 PDF가 손상되었습니다. 이 기존 뷰 파일을 렌더링하는 방법? render_to_string의 형식 또는 형식을 지정해야 할 수도 있습니다. – maxs