我正在尝试安装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',
}

我的控制器:

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

非常感谢提前