我刚刚对我的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
我可以使用
构建/安装gemgem build my-engine.gemspec
gem install my-engine-0.0.1.gem
之后rails -v
开始工作。*看起来这似乎不是必要的,这让我担心Rails可能正在使用代码的内置/安装版本而不是实时源代码。我做错了什么?
*也就是说,它运行,即使它抱怨“Bundler正在使用为不同的gem创建的binstub”。可能是因为它不喜欢gem命名为my-engine
但ENGINE_PATH
有my/engine
的事实?
答案 0 :(得分:0)
在引擎根目录中调用rails -v
是没有意义的,因为在需要在rails应用程序中加载引擎之后引擎是一个gem,除非你的结构像普通的rails app而不是引擎宝石。
所以基本上,当你运行rails -v
时,它会尝试将你的引擎加载为gem而不是普通的rails应用程序,因此如果它没有安装在你的环境中,它会抱怨。
答案 1 :(得分:0)
看起来这台机器上的本地宝石设置已经损坏 - 即使我创建了一个全新的无关引擎,它仍然抱怨无法找到my-engine
。 rm -r ~/.rvm/gems/ruby-2.2.1*
/ gem install rails
修复了问题(但代价是不得不重新安装一堆宝石)。