delayed_job给出“NameError:uninitialized constant”

时间:2012-07-19 17:21:13

标签: ruby-on-rails delayed-job nameerror

我正在尝试移动当前的工作任务(在生产和控制台中)在Rails 2应用程序中使用delayed_job,但不断收到错误:

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

的Gemfile

gem "delayed_job", "2.0.7"
gem "daemons", "1.0.10"

1 个答案:

答案 0 :(得分:1)

好吧,经过多次敲击,我想出来了,所以我发布这个来帮助下一个人。问题是它无法找到barby libs,所以我在课程开头添加了一个require:

require "barby/outputter/rmagick_outputter"
require "barby/barcode/code_128"