wicked_pdf is not rendering header

試著忘記壹切 提交于 2019-12-01 15:27:57

问题


        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 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.

This is Mac OS, Rails 3.2.1, ruby 1.9


回答1:


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')
}

It works well for me.



来源:https://stackoverflow.com/questions/11529912/wicked-pdf-is-not-rendering-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!