我正在尝试移动当前工作任务(在生产和控制台中)以在 Rails 2 应用程序中使用延迟作业,但不断收到错误消息:
ThermalImageJob failed with NameError: uninitialized constant Barby::Code128B
我仔细研究了其他人的代码以寻找无济于事的答案。这是我的代码:
/lib/thermal_image_job.rb
class ThermalImageJob < Struct.new(:order_id)
def perform
order = Order.find(order_id)
order.tickets.each do |ticket|
ticket.barcodes.each do |barcode|
barcode.generate_thermal_image
end
end
end
end
/app/controllers/orders_controller.rb
Delayed::Job.enqueue(ThermalImageJob.new(@order.id))
/app/models/barcode.rb
def generate_thermal_image(format=:gif)
filename = "#{barcode}_thermal.#{format}"
temp_file_path = File.join("#{RAILS_ROOT}", 'tmp', filename)
unless FileTest.exists?(temp_file_path)
barcode_file = File.new(temp_file_path, 'w')
code = Barby::Code128B.new(barcode)
....
end
宝石文件
gem "delayed_job", "2.0.7"
gem "daemons", "1.0.10"