这是 wicked pdf 文档中指定的内容:
WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf_file.pdf", :template => 'templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
:footer => {:content => render_to_string({:template => 'templates/pdf_footer.html.erb', :layout => 'pdfs/layout_pdf'})}
)
我得到的是 ActionView::MissingTemplate
即使我的目录中有 pdf.html.erb 。我在应用程序控制器中使用 gen_pdf 方法,并在views/application 文件夹中使用等效的 pdf.html.erb 。我缺少什么。
不要使用template
.
我遇到了和你一样的问题。当您在控制器操作中执行 PDF 操作时,与在邮件程序或其他操作中执行操作相比,您必须以完全不同的方式呈现 PDF。
首先,使用template
行不通的。还有一些其他细微差别,但这是我的实现,您可以以此为基础:
notification_mailer.rb
def export
header_html = render_to_string( partial: 'exports/header.pdf.erb',
locals: { report_title: 'Emissions Export' } )
body_html = render_to_string( partial: "exports/show.pdf.erb" )
footer_html = render_to_string( partial: 'exports/footer.pdf.erb' )
@pdf = WickedPdf.new.pdf_from_string( body_html,
orientation: 'Landscape',
margin: { bottom: 20, top: 30 },
header: { content: header_html },
footer: { content: footer_html } )
# Attach to email as attachment.
attachments["Export.pdf"] = @pdf
# Send email. Attachment assigned above will automatically be included.
mail( { subject: 'Export PDF', to: '[email protected]' } )
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)