Search code examples
ruby-on-railsrubyactiverecord

uninitialized constant ActiveRecord


2.0.0-p247 :006 > load './app/models/user.rb'                                                                                                                                                     
NameError: uninitialized constant ActiveRecord                                                                                                                                                    
        from /home/action/iAuth/app/models/user.rb:1:in `<top (required)>'                                                                                                                        
        from (irb):6:in `load'                                                                                                                                                                    
        from (irb):6                                                                                                                                                                              
        from /home/action/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'   

Below is my User Model.

class User < ActiveRecord::Base
end

When i try to load my user.rb in my irb, i get the above error.


Solution

  • start your irb session with

    rails console

    and not:

    irb

    rails console would load your rails environment and your model for you, so you can do things like:

    User.all or User.new without loading the class as it has been preloaded by rails console already