2

我有一个导轨控制器:

class Console::AccesorBillsController < ConsoleController
  ...
  def bill
    AcceccorBill.new.run

    render :nothing => true
  end
end

我在那里创建新模型并使用兔子页面( http://rubybunny.info/articles/getting_started.html)中的示例运行一个方法:

require "bunny"

class AcceccorBill
  def initialize()
  end

  def run
    conn = Bunny.new
    conn.start

    ch  = conn.create_channel
    x   = ch.fanout("nba.scores")

    ch.queue("joe",   :auto_delete => true).bind(x).subscribe do |delivery_info, metadata, payload|
      puts "#{payload} => joe"
    end

    ch.queue("aaron", :auto_delete => true).bind(x).subscribe do |delivery_info, metadata, payload|
      puts "#{payload} => aaron"
    end

    ch.queue("bob",   :auto_delete => true).bind(x).subscribe do |delivery_info, metadata, payload|
      puts "#{payload} => bob"
    end

    x.publish("BOS 101, NYK 89").publish("ORL 85, ALT 88")

    conn.close
  end
end

但我总是得到这个错误:

NameError - uninitialized constant AcceccorBill::Bunny:
  (gem) activesupport-3.1.12/lib/active_support/dependencies.rb:507:in `load_missing_constant'
  (gem) activesupport-3.1.12/lib/active_support/dependencies.rb:181:in `block in const_missing'
  (gem) activesupport-3.1.12/lib/active_support/dependencies.rb:179:in `const_missing'
  (gem) rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
  app/ext/acceccor_bill.rb:6:in `initialize'
  app/controllers/console/accesor_bills_controller.rb:17:in `bill'
  (gem) actionpack-3.1.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  (gem) actionpack-3.1.12/lib/abstract_controller/base.rb:167:in `process_action'
  (gem) actionpack-3.1.12/lib/action_controller/metal/rendering.rb:10:in `process_action'

有谁知道如何解决这个问题?

PS:我通过捆绑器安装了gem,它看起来require不起作用。

4

1 回答 1

3

解决了。

我忘了要求bundler。所以我只是在文件的开头添加了这个:

require "bundler/setup"
require "bunny"

仅此而已。

于 2013-07-04T11:56:20.787 回答