【发布时间】:2015-09-07 01:26:02
【问题描述】:
我正在使用 pdfkit gem,它正在使用 wkhtmltopdf-binary gem 中的 wkhtmltopdf 进行开发。
在服务器上 pdfkit 失败并出现错误
undefined method `chomp' for nil:NilClass
在
shared/bundle/ruby/2.1.0/gems/pdfkit-0.8.2/lib/pdfkit/configuration.rb:22:in `wkhtmltopdf'
失败的方法是
def wkhtmltopdf
@wkhtmltopdf ||= (defined?(Bundler::GemfileError) && File.exists?('Gemfile') ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
end
经过一些调试后,从该方法调用 `bundle exec which wkhtmltopdf' 似乎返回空白。
当从应用程序根目录中的命令行调用时,它会给出
/var/www/<app>/shared/bundle/ruby/2.1.0/bin/wkhtmltopdf
我已尝试从初始化程序初始化@wkhtmltopdf 的值,如下所示
PDFKit.configure do |config|
if Rails.env.production?
config.wkhtmltopdf = "/var/www/<app>/shared/bundle/ruby/2.1.0/bin/wkhtmltopdf"
end
config.default_options = {
:page_size => 'A4',
}
end
但我仍然遇到同样的错误。即它仍在尝试运行“which”命令并以空白失败。
【问题讨论】:
标签: ruby-on-rails ruby bundler wkhtmltopdf pdfkit