如何在IRB中要求ActiveRecord

时间:2018-05-05 15:43:32

标签: ruby activerecord rubygems require irb

我想在我的IRB会话中加载ActiveRecord gem,但以下内容不起作用:

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中的宝石路径:

        2.4.1 :012 > Gem.path
     => [
          "/Users/robskrob/.rvm/gems/ruby-2.4.1", 
          "/Users/robskrob/.rvm/gems/ruby-2.4.1@global
        ]

这是我的活跃记录宝石:

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 gems加载到我的IRB会话中?

我查看了this postthis post,但我无法从问题或答案中找到解决方案。

1 个答案:

答案 0 :(得分:5)

尝试require('active_record')

如果你看看gem Github repo,实际的文件名是active_record.rb,所以上面的代码应该可以工作。

https://github.com/rails/rails/tree/master/activerecord/lib