delayed_job выдает NameError: неинициализированная константа

Я пытаюсь переместить текущую рабочую задачу (в производстве и в консоли), чтобы использовать delayed_job в приложении 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

/приложение/контроллеры/orders_controller.rb

Delayed::Job.enqueue(ThermalImageJob.new(@order.id))

/приложение/модели/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"

person Dawn Green    schedule 19.07.2012    source источник


Ответы (1)


Что ж, после долгих головокружений я понял это, поэтому я публикую это, чтобы помочь следующему человеку. Проблема заключалась в том, что он не мог найти библиотеки barby, поэтому я добавил требование в начале своего класса:

require "barby/outputter/rmagick_outputter"
require "barby/barcode/code_128"
person Dawn Green    schedule 20.07.2012
comment
На самом деле это было в постустановочном сообщении от Барби - Barby no longer require all barcode symbologies by default. You'll have to require the ones you need. For example, if you need EAN-13, require 'barby/barcode/ean_13'; For a full list of symbologies and their filenames, see README. - person sevenseacat; 16.06.2014