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