ruby-on-rails - wicked_pdf 的未知格式

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

我正在尝试安装 wicked_pdf,以便在我的 Rails 应用程序上生成 2 个用户之间的预填充契约(Contract)。

我觉得我已经正确安装了 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',
}

我的 Controller :

#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>

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

# bookings/show.pdf.erb

<h1>PDF test</h1>

提前致谢

最佳答案

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

关于ruby-on-rails - wicked_pdf 的未知格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033445/

相关文章:

ruby-on-rails - namespace 中以参数开头的 Rails 路由资源

ruby-on-rails - 模型应该在 Rails 中命名吗?

python - Django - pdf 响应编码错误 - reportlab

php - WKPDF系统错误?

ruby-on-rails - Rails 自定义生成器组

mysql - 不同的mysql超时是什么意思

ruby-on-rails - 生成带有页眉/页脚的大量页面的 pdf 时出现 wkhtmltopdf 错误

php - 如何在 Linux 上使用 PHP 将 HTML/CSS 转换为 PDF

cakephp - CakePHP 中的 TCPDF 奇怪问题

使用 PDFBox 1.8.9 文本重叠的 PDF 到图像