我正在尝试安装wicked_pdf,以便在我的Rails应用程序上的两个用户之间生成预先填写的合同。
我感觉我已经正确地安装了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“时,...but不是PDF。
# bookings/show.pdf.erb
<h1>PDF test</h1>提前谢谢你
发布于 2021-10-14 07:21:28
我知道这是一个相当古老的问题,但是您可以使用gem wkhtmltopdf-binary-edge而不是常规的wkhtmltopdf-binary gem。这对我很管用。
https://stackoverflow.com/questions/36033445
复制相似问题