5
我最近决定采取一些功能,我已经在我的几个Rails应用程序,并将其提取到引擎。我现在已经完成了引擎,并且正在尝试将完成的宝石安装到我的一个应用程序中。自定义宝石在/供应商/宝石不加载
这个特殊的宝石不是我想公开的东西,所以我打包了宝石gem build my_gem.gemspec
,然后把打包好的宝石放到我的应用程序的vendor/gems文件夹中。然后,我将gem 'my_gem', '0.0.1', :path => 'vendor/gems'
添加到我的gemfile并运行bundle install
。
但不幸的是,Rails的似乎并没有被加载的宝石,我似乎无法手动要求它:
$ bundle exec rails console --sandbox
Loading development environment in sandbox (Rails 3.2.11)
Any modifications you make will be rolled back on exit
irb(main):001:0> MyGem
NameError: uninitialized constant MyGem
from (irb):1
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
irb(main):002:0> require 'my_gem'
LoadError: cannot load such file -- my_gem
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from (irb):2
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
难道我做错了什么?我该如何解决?
编辑:这里是我的宝石环境信息。
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.16
- RUBY VERSION: 1.9.3 (2012-02-16 patchlevel 125) [i386-mingw32]
- INSTALLATION DIRECTORY: c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe
- EXECUTABLE DIRECTORY: c:/RailsInstaller/Ruby1.9.3/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1
- c:/Users/Ajedi32/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
“gem目录”意味着我正在使用未打包的gem,对吧?那是我应该怎么做的?因为目前的方式(我使用的是封装的gem),':path =>'vendor/gems/my_gem'会给出错误'The path'C:/ Users/Ajedi32/my_app/vendor/gems/my_gem 'does not exist.' – Ajedi32 2013-04-28 21:33:28
你需要在该目录中有一个'my-gem.gemspec'文件。您也可以将该目录放在Git版本控制下的某个位置,然后将路径指向可检查目录 – Tilo 2013-04-28 21:50:14
的URL的URL,那么我无法使用捆绑版本的gem? I.E. 'my_gem.gem'?或者是'GEM_PATH'变量的用途是什么? – Ajedi32 2013-04-28 21:58:27