5

私は最近、Rails アプリのいくつかにあるいくつかの機能をエンジンに抽出することにしました。エンジンが完成し、完成した宝石をアプリの 1 つにインストールしようとしています。

この特定の gem は公開したくないので、gem をパッケージ化し、パッケージ化された gem をgem build my_gem.gemspecアプリケーションの vendor/gems フォルダーに配置しました。次に、gem 'my_gem', '0.0.1', :path => 'vendor/gems'gemfile に追加して実行しましたbundle install

残念ながら、Rails は gem をロードしていないようで、手動で要求することはできないようです:

$ 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 環境情報です。

$ 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/
4

1 に答える 1

4

入力gem envして、Ruby が gem を検索している場所を確認します。

次に、gem を配置したディレクトリを GEM_PATH 環境変数に追加します。例えば:

  export GEM_PATH="./vendor/gems:$GEM_PATH"

参照: http://docs.rubygems.org/read/chapter/12

Gemfile を使用している場合は、次のようにすることもできます。

  gem 'my-gem', '0.0.1', :path => 'vendor/gems/my-gem'

(gem ディレクトリの名前をパスに追加する必要があります)

于 2013-04-28T21:23:40.860 に答える