从rails中的控制器访问gem函数

时间:2014-01-13 08:27:51

标签: ruby-on-rails ruby

我在gemfile中有一个bitcoin-ruby,如何从我的rails控制器访问以下内容?

key = Bitcoin::generate_key
@address = Bitcoin::pubkey_to_address(key[1])

错误:

uninitialized constant HomeController::Bitcoin

的Gemfile:

gem "bitcoin-ruby", "~> 0.0.4"

我尝试用普通的红宝石做到这一点,(安装比特币 - 红宝石成功)

require 'bitcoin-ruby'

引发以下错误。

/home/p4/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- bitcoin-ruby (LoadError)
from /home/p4/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from bitcoin.rb:2:in `<main>'

可能是因为我对链接ruby库缺乏了解,我错在哪里?

1 个答案:

答案 0 :(得分:2)

根据README,您需要添加一个require键:

gem "bitcoin-ruby", "~> 0.0.4", require: 'bitcoin'