Rails + bunny gem - 没有这样的文件加载 - 兔子

时间:2013-07-04 11:47:59

标签: ruby-on-rails ruby-on-rails-3 bundler rabbitmq

我有一个rails控制器:

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

    render :nothing => true
  end
end

我在那里创建新模型并使用bunny的页面(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'

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

P.S。:我通过bundler安装了gem,看起来require不起作用。

1 个答案:

答案 0 :(得分:3)

解决了它。

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

require "bundler/setup"
require "bunny"

就是这样。