ruby-on-rails-4 – 在首先安装宝石本身的情况下,无法在Gem / Engine项目中运行Rails

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-4 – 在首先安装宝石本身的情况下,无法在Gem / Engine项目中运行Rails前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚检查了我的Rails Engine项目,当(在捆绑安装后)我在其根目录中调用了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 build my-engine.gemspec
gem install my-engine-0.0.1.gem

之后,rails -v开始工作.但是,这似乎并不是必须的,而且它使我担心Rails可能正在使用内置/安装的代码而不是直接的源代码.我究竟做错了什么?

就是说,它运行,即使它抱怨“Bundler正在使用为不同的宝石创建的binstub”.可能是因为它不喜欢宝石被命名为我的引擎,但是ENGINE_PATH有我的/引擎?

解决方法

在引擎根目录中调用rails -v是没有意义的,因为引擎是一个gem,所有这些都需要在rails应用程序中加载,除非您将其结构化为普通的rails应用程序而不是引擎gem.

所以基本上,当您运行rails -v时,它将尝试将引擎作为宝石加载,而不是正常的rails应用程序,因此如果引擎没有安装在您的环境中,它将会抱怨.

猜你在找的Ruby相关文章