wicked_pdf格式未知

时间:2016-03-16 10:48:52

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

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

提前多多感谢

0 个答案:

没有答案