首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails + bunny -没有这样的文件可加载-- bunny

Rails + bunny -没有这样的文件可加载-- bunny
EN

Stack Overflow用户
提问于 2013-07-04 19:47:59
回答 1查看 1.1K关注 0票数 2

我有一个rails控制器:

代码语言:javascript
复制
class Console::AccesorBillsController < ConsoleController
  ...
  def bill
    AcceccorBill.new.run

    render :nothing => true
  end
end

我在那里创建了一个新的模型,并运行了一个来自bunny页面(http://rubybunny.info/articles/getting_started.html)的例子的方法:

代码语言:javascript
复制
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

但我总是得到这样的错误:

代码语言:javascript
复制
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'

有人知道怎么解决这个问题吗?

附言:我通过bundler安装了gem,但看起来require不能工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-04 19:56:21

解决了它。

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

代码语言:javascript
复制
require "bundler/setup"
require "bunny"

仅此而已。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17469513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档