wicked_pdf 不呈现标题 [英] wicked_pdf is not rendering header

查看:41
本文介绍了wicked_pdf 不呈现标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        render :pdf => "file_name",
                     :layout      => 'pdf.html.erb',
                     :template    => 'transactions/show.pdf.erb',
                      :wkhtmltopdf => WICKED_PDF_BIN,
                      :show_as_html => true,
                    :layout => 'pdf.html.erb',
                    :header => {:html => { :template => 'shared/header.pdf.erb'}}

PDF 生成正常,不幸的是我没有看到标题.我可以在主布局中粘贴标题,它也可以正常工作.在我看来,上面的标题行没有被处理.文件名 'header.pdf.erb' 似乎无关紧要.我可以将它指向一个不存在的文件,它不会引发任何错误.

PDF is generated fine, unfortunately I do not see the header. I can stick the header in the main layout and it works fine too. It seems to me that the header line above is not being processed. The filename 'header.pdf.erb' does not seem to matter. I can point it to a file that does not exist and it throws no error.

这是 Mac OS,Rails 3.2.1,ruby 1.9

This is Mac OS, Rails 3.2.1, ruby 1.9

推荐答案

您可能只想将模板呈现为字符串并将其分配给标题的内容.试试这个:

You may want to simply render the template as a string and assign it to the header's content. Try this out:

header: {
  content: render_to_string(template: 'header.pdf.haml')
}

对我来说效果很好.

这篇关于wicked_pdf 不呈现标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆