我正在尝试在我的操作中使用 wicked pdf 渲染 pdf。
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "reciept"
end
end
end
这对于 html 格式来说效果很好,但给了我
Missing template /reciept with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
安装了 gem 'wicked_pdf' 和 'wkhtmltopdf-binary'。 使用导轨 7. 任何帮助都会得到帮助。
我以为这是 gem 的问题,所以重新安装了 gem,但没有任何改变。
render pdf: "recipt", template: 'pdf/recipt', formats: [:html]
如果使用recipt.html.erb,则必须将格式告诉html,否则会在rails 7中给出缺少模板的错误。对于使用.pfd.erb文件,没有格式可以工作。
如果您从 Rails 6 移动到 Rails 7,那么您需要删除针对任何属性(包括布局)定义的
.html.erb
。
render pdf: "receipt", template: 'pdf/receipt.html.erb', layout: "pdf.html.erb", formats: [:html]
render pdf: "receipt", template: 'pdf/receipt', layout: "pdf", formats: [:html]