ROR:图像未在 wicked_pdf 的 pdf 中呈现

ROR: Image not getting rendered in wicked_pdf's pdf

这里我不是在谈论带有wicked_pdf_image_tag的图像。那些运作良好。但是当我下载 pdf 时它没有渲染图像。

它呈现的像一个小盒子。 Click here

File.html.haml

%img{src: "/assets/#{CONFIG[$skey]['main_logo_path']}"}

File.pdf.erb

<%= wicked_pdf_image_tag(CONFIG[$skey]['main_logo_path'],alt: "Logo", class: "mt-md mb-md")  %>

使用的宝石:

wicked_pdf (2.1.0)
wkhtmltopdf-binary (0.12.6.5)

请帮忙!

我正在查看 wicked_pdf_image_tag https://github.com/mileszs/wicked_pdf/blob/2.1.0/lib/wicked_pdf/wicked_pdf_helper.rb#L21 实现,它尝试在 /public/images/img 处选择图像,但您的图像在 /assets

改用image_tag "file:///#{WickedPdf::WickedPdfHelper.root_path.join('assets', CONFIG[$skey]['main_logo_path'])}", alt: "Logo", class: "mt-md mb-md")

如果有人仍在寻找此问题的解决方案。答案如下:

<%= image_tag wicked_pdf_asset_base64("logo.png") %>

对 assest/images 文件夹中的图像使用 image_tag wicked_pdf_asset_base64。