我想使用 rake 任务在 cron 作业 rails 时运行生成 pdf。当我通过控制台上的这个命令运行这个 rake 任务时,它生成 pdf 很好
bundle exec rake auto_invoice_email
如果我给出这个命令
which wkhtmltopdf
然后我有这个路径“/usr/bin/wkhtmltopdf”
但是当我通过cron作业运行它时,我有这个错误
rake aborted!
Failed to execute:
"/usr/bin/wkhtmltopdf" -q - -
Error: PDF could not be generated!
Tasks: TOP => auto_invoice_email
(See full trace by running task with --trace)
我如何以及在哪里可以为 cron 作业指定 wkhtmltopdf 的路径
有什么帮助吗?
这是 rake 任务
require 'rubygems'
require 'wicked_pdf'
require 'erb'
require 'date'
task :auto_invoice_email => :environment do
#$PATH = '/usr/bin/wkhtmltopdf'
include ApplicationHelper
users = User.find_subscribers
unless users.blank?
users.each do |user|
@user = user
content = File.read "#{Rails.root}/app/views/accountings/generate_invoice_pdf_rake.html.erb"
template = ERB.new(content)
html_content = template.result(binding)
pdf= WickedPdf.new.pdf_from_string(html_content, :wkhtmltopdf => '/usr/bin/wkhtmltopdf')
name = "#{Rails.root}/public/#{user.subscriber.downcase+" "+Time.now.to_s}.pdf"
File.open(name, 'wb') do |file|
file << pdf
end
end
end
结尾
谢谢