【问题标题】:delayed_job gives "NameError: uninitialized constant"delay_job 给出“NameError:未初始化的常量”
【发布时间】:2012-07-19 17:21:13
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 这实际上是来自 barby 的安装后消息 - 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.
    猜你喜欢
    • 1970-01-01
    • 2015-01-19
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 2016-06-12
    • 2015-03-01
    相关资源
    最近更新 更多