wicked_pdf is not rendering header

2019-02-21 20:34发布

        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条回答
迷人小祖宗
2楼-- · 2019-02-21 20:44

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.

查看更多
登录 后发表回答