r-6ren">
gpt4 book ai didi

ruby-on-rails - 在 irb : "NameError: uninitialized constant Gem from (irb)" 中找不到 gem

转载 作者:数据小太阳 更新时间:2023-10-29 06:52:55 28 4
gpt4 key购买 nike

当我运行 Rails 应用程序时,它会正确找到我安装的所有 gem。

这是我第一次尝试从 irb 内部调用一些 gem,但找不到它们。

blocke:~$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'rails'
LoadError: no such file to load -- rails
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (irb):2
irb(main):003:0>

当我运行“gem environment”时,这是我得到的:

blocke:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/blocke/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- :sources => ["http://gemcutter.org", "http://gems.rubyforge.org/", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gemcutter.org
- http://gems.rubyforge.org/
- http://gems.github.com

根据 irb,gem 路径是相同的,只是顺序相反:

blocke:~$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> Gem.path
=> ["/home/blocke/.gem/ruby/1.8", "/usr/lib/ruby/gems/1.8"]

最佳答案

它不起作用,因为它找不到“rails.rb”文件(我认为 rails gem 中没有这样的文件)。

您可以要求特定的 Rails 组件,例如“activerecord”:

require 'rubygems'
require 'activerecord'

或者使用 'gem' 命令,像这样:

require 'rubygems'
gem 'rails'

关于ruby-on-rails - 在 irb : "NameError: uninitialized constant Gem from (irb)" 中找不到 gem ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1689725/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com