【问题标题】:Unknown format with wicked_pdfwicked_pdf 的未知格式
【发布时间】:2016-07-02 04:49:37
【问题描述】:

我正在尝试安装 wicked_pdf,以便在我的 Rails 应用程序上的 2 个用户之间生成预先填写的合同。

我觉得我已经正确安装了 wicked_pdf,但我收到“ActionController::UnknownFormat”错误。

我做了什么:

# Gemfile

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

无论是否取消注释“exe ...”行(一个接一个),我仍然得到错误:

# initializers/wicked_pdf.rb

WickedPdf.config = {
# Path to the wkhtmltopdf executable: This usually isn't needed if using
# one of the wkhtmltopdf-binary family of gems.
# exe_path: '/usr/local/bin/wkhtmltopdf',
#   or
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')

# Layout file to be used for all PDFs
# (but can be overridden in `render :pdf` calls)
# layout: 'pdf.html',
}

我的控制器:

#bookings_controller.rb

class BookingsController < ApplicationController
def show
  @booking = Booking.find(params[:id])
  respond_to do |format|
    format.html
    format.pdf do
      render pdf: "test_wicked_pdf"
    end
  end
  authorize @booking # For Pundit
end

当我转到 localhost:3000/bookings/135 时,渲染 HTML 正在工作......

# bookings/show.html.erb

<h1>PDF test</h1>

...但当我在控制器中注释掉“# format.html”时不是 PDF

# bookings/show.pdf.erb

<h1>PDF test</h1>

提前非常感谢

【问题讨论】:

  • 您能否在 config/initializers 路径中检查您的 mime_types.rb 文件。你有没有提到以下行 - Mime::Type.register "application/pdf", :pdf
  • 是的,我有这条线。
  • 你能显示调用 BookingController 的显示操作的视图代码(可能是视图中的 link_to 标记)吗?
  • 感谢您,我想我发现了错误,我直接输入了 url,但是当我使用 link_to 帮助器并指定格式时,它可以工作: - 非常感谢

标签: ruby-on-rails pdf-generation wkhtmltopdf wicked-pdf


【解决方案1】:

我知道这是一个很老的问题,但您可以使用 gem wkhtmltopdf-binary-edge 代替常规的 wkhtmltopdf-binary gem。它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多