1

我正在尝试移动当前工作任务(在生产和控制台中)以在 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"
4

1 回答 1

1

好吧,经过多次头部撞击,我想通了,所以我发布这个来帮助下一个人。问题是它找不到 barby 库,所以我在课程开始时添加了一个要求:

require "barby/outputter/rmagick_outputter"
require "barby/barcode/code_128"
于 2012-07-20T07:05:39.887 回答