1
我有一個Rails控制器:的Rails +兔子寶石 - 沒有這樣的文件加載 - 兔子
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'
有誰知道如何解決呢?
P.S .:我通過捆綁軟件安裝了gem,它看起來像require
不起作用。
每次調用Console :: AccesorBillsController.bill時,都會創建一個新的「Bunny」連接。我認爲如果連接可以重複使用pub/sub,則應該只創建一次。你是否更好地重構了代碼?如果是這樣,我想知道你是如何做到的。謝謝! – philipjkim
@philipjkim這只是一個例子來測試兔子的作品,沒有更多。 – ExiRe