How to require ActiveRecord In IRB

2019-03-01 05:04发布

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>'

and Neither is this one:

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>'

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/

How do I load one of those ActiveRecord gems into my IRB session?

I have looked at this post and this post, but I could not source a solution from either the questions or the answers.

1条回答
不美不萌又怎样
2楼-- · 2019-03-01 05:41

Try require('active_record')

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/rails/rails/tree/master/activerecord/lib

查看更多
登录 后发表回答