【发布时间】:2019-02-28 06:23:27
【问题描述】:
所以我正在尝试开发一个应用程序,让您可以将产品转换为带有二维码的标签。使用 gem PDFKit 和 wkhtmltopdf 它可以在本地正常工作。但是在 Heroku 上它给我一个 HTTP 406 和以下 rails 错误:ActionController::UnknownFormat (OrderController#print is missing a template for this request format and variant. request.formats: ["application/pdf"] request.variants: [])。我搜索了论坛,但似乎找不到遇到同样问题的人。我还按照 PDFKit github 上的指南了解 heroku 的使用,link to guide。这意味着我同时拥有 wkhtmltopdf-binary gem 和 wkhtmltopdf-heroku gem。
相关代码sn-ps:
#in app/views/order/show.html.erb
<%= link_to "Print QR-code", print_order_path(@order, :format => :pdf), class 'btn btn-primary' %>
#in app/config/initializers/pdfkit.rb
PDFKit.configure do |config|
if File.executable? 'app/.apt/usr/local/bin/wkhtmltopdf'
config.wkhtmltopdf = 'app/.apt/usr/local/bin/wkhtmltopdf'
end
#app/controllers/order_controller
def print
@order = Order.find(params[:id])
end
#app/views/order/print.html.erb
<div style="display: inline-block">
<table class="QR" style="width:100%">
<tr style="margin:30px">
<td class="QR">
<% @qr = RQRCode::QRCode.new(@order.qr_code.to_s, :size => 6)%>
<%= raw @qr.as_svg(offset:0, color: '000',shape_rendering: 'crispEdges', module_size:4) %>
</td>
<td style="font-size:50px;padding:20px; text-align:center">
<%=@order.garment.to_s%><br>
<%=@order.size.to_s%>
</td>
</tr>
</table>
</div>
使用 srng 提供的 respond_to 添加块后,我现在收到以下错误:
ActionView::MissingTemplate(Missing template order/print, application/print with {:locale =>[:sv], :formats =>[:pdf], :variants => [], :handlers => [:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}
【问题讨论】:
-
wkhtmltopdf-heroku 推荐not touching the binary path。这有点矛盾,但也许可以尝试注释掉 PDFKit 配置?
-
我把它注释掉了,但它仍然产生同样的错误。我在想这可能是一个错字,但这没有意义,因为它可以在本地服务器上运行。我对 rails 不够精通,无法准确确定发生 unknownformat 错误时发生的情况。我假设它正在尝试解析 .pdf 但由于 wkhtmltopdf 无法正常工作而没有得到解析?
-
你能发布你的控制器方法吗?在处理文件下载时,我经常遇到 406。
-
添加到帖子@srng
标签: ruby-on-rails heroku wkhtmltopdf pdfkit