如何在IRB中要求ActiveRecord [英] How to require ActiveRecord In IRB
问题描述
我想在我的IRB会话中加载ActiveRecord gem,但以下操作无效:
I would like to load the ActiveRecord gem in my IRB session, but the following is not working:
require 'activerecord'
2.4.1 :004 > require 'activerecord'
LoadError: cannot load such file -- activerecord
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):4
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
这都不是:
2.4.1 :018 > require 'activerecord-5.1.2'
LoadError: cannot load such file -- activerecord-5.1.2
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:120:in `require'
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:120:in `require'
from (irb):18
from /Users/robskrob/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>'
这是我在irb中的宝石路径:
This is my Gem path in irb:
2.4.1 :012 > Gem.path
=> [
"/Users/robskrob/.rvm/gems/ruby-2.4.1",
"/Users/robskrob/.rvm/gems/ruby-2.4.1@global
]
这是我的活动记录宝石:
and here are my active record gems:
ls /Users/robskrob/.rvm/gems/ruby-2.4.1/gems/activere
activerecord-4.2.10/ activerecord-5.1.2/ activerecord-5.1.4/ activerecord-5.1.6/
activerecord-5.0.0.1/ activerecord-5.1.3/ activerecord-5.1.5/ activeresource-5.0.0/
如何将这些ActiveRecord宝石之一加载到我的IRB会话中?
How do I load one of those ActiveRecord gems into my IRB session?
我看过< a href = https://stackoverflow.com/questions/39694428/requiring-activerecord-on-irb-ruby-no-rails?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa>此帖子和此帖子但是我很酷
I have looked at this post and this post, but I could not source a solution from either the questions or the answers.
推荐答案
尝试 require('active_record' )
如果您查看gem Github存储库,则实际文件名为active_record.rb,因此上述代码应该可以使用。
If you take a look at the gem Github repo the actual file name is active_record.rb so the above code should work.
https://github.com。 com / rails / rails / tree / master / activerecord / lib
这篇关于如何在IRB中要求ActiveRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!