在没有首先安装gem本身的情况下,无法在Gem / Engine项目中运行Rails

时间:2015-04-13 23:33:57

标签: ruby-on-rails-4 gem rails-engines

我刚刚对我的Rails Engine项目进行了新的检查,当我(在bundle install之后)在其根目录中调用rails -v时,我得到了一个LoadError,其中包含Rails似乎在寻找我正在努力构建的宝石/引擎:

my-engine dmoles$ rails -v
/Users/dmoles/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'my-engine' (>= 0) among 117 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/dmoles/.rvm/gems/ruby-2.2.1:/Users/dmoles/.rvm/gems/ruby-2.2.1@global', execute `gem env` for more information
    from /Users/dmoles/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
    from /Users/dmoles/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /Users/dmoles/.rvm/gems/ruby-2.2.1/bin/rails:22:in `<main>'

按照建议运行gem env不再提供启示:

my-engine dmoles$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.6
  - RUBY VERSION: 2.2.1 (2015-02-26 patchlevel 85) [x86_64-darwin14]
  - INSTALLATION DIRECTORY: /Users/dmoles/.rvm/gems/ruby-2.2.1
  - RUBY EXECUTABLE: /Users/dmoles/.rvm/rubies/ruby-2.2.1/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/dmoles/.rvm/gems/ruby-2.2.1/bin
  - SPEC CACHE DIRECTORY: /Users/dmoles/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/dmoles/.rvm/rubies/ruby-2.2.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-14
  - GEM PATHS:
     - /Users/dmoles/.rvm/gems/ruby-2.2.1
     - /Users/dmoles/.rvm/gems/ruby-2.2.1@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/dmoles/.rvm/gems/ruby-2.2.1/bin
     - /Users/dmoles/.rvm/gems/ruby-2.2.1@global/bin
     - /Users/dmoles/.rvm/rubies/ruby-2.2.1/bin
     - /Users/dmoles/.rvm/bin
     - /Users/dmoles/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/git/bin

我可以使用

构建/安装gem
gem build my-engine.gemspec
gem install my-engine-0.0.1.gem

之后rails -v开始工作。*看起来这似乎不是必要的,这让我担心Rails可能正在使用代码的内置/安装版本而不是实时源代码。我做错了什么?


*也就是说,它运行,即使它抱怨“Bundler正在使用为不同的gem创建的binstub”。可能是因为它不喜欢gem命名为my-engineENGINE_PATHmy/engine的事实?

2 个答案:

答案 0 :(得分:0)

在引擎根目录中调用rails -v是没有意义的,因为在需要在rails应用程序中加载引擎之后引擎是一个gem,除非你的结构像普通的rails app而不是引擎宝石。

所以基本上,当你运行rails -v时,它会尝试将你的引擎加载为gem而不是普通的rails应用程序,因此如果它没有安装在你的环境中,它会抱怨。

答案 1 :(得分:0)

看起来这台机器上的本地宝石设置已经损坏 - 即使我创建了一个全新的无关引擎,它仍然抱怨无法找到my-enginerm -r ~/.rvm/gems/ruby-2.2.1* / gem install rails修复了问题(但代价是不得不重新安装一堆宝石)。