How to require ActiveRecord In IRB

六月ゝ 毕业季﹏ 提交于 2019-12-04 04:59:35

问题


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:


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



来源:https://stackoverflow.com/questions/50191222/how-to-require-activerecord-in-irb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!