【发布时间】:2013-10-19 02:52:17
【问题描述】:
我在 Rails 应用程序中使用 gem 'pdfkit'。 它在 Heroku 上运行良好,但在我的 iMac 上出现错误。
错误:
command failed: "/users/myname/sites/ndeavor2/bin/wkhtmltopdf-amd64"
应用程序wkhtmltopdf-amd64在错误指示的文件夹中!
我的 application.rb 有:
config.middleware.use "PDFKit::Middleware", :print_media_type => true
我有一个名为 pdfkit.rb 的初始化程序
PDFKit.configure do |config|
config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
end
感谢您的帮助!
更新1
我下载了wkhtmltopdf.app,放在和amd64版本一样的位置。
我把 pdfkit.rb 改成:
PDFKit.configure do |config|
config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s if Rails.env.production?
config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf.app').to_s if Rails.env.development?
end
我还将 wkhtmltopdf.app 的副本放入应用程序文件夹并尝试了这个:
config.wkhtmltopdf = '/applications/wkhtmltopdf.app' if Rails.env.development?
我收到此错误:
command failed:
【问题讨论】:
-
好吧,我马上就想知道为什么它调用
wkhtmltopdf-amd64,而 iMac 将是英特尔架构。这看起来很可疑。 -
更新了我的答案。忘记了让事情变得可执行。我喜欢你的解决方案,它能够非常彻底地区分开发环境和生产环境。
标签: ruby-on-rails wkhtmltopdf pdfkit