简体   繁体   中英

Ruby on Rails: undefined method for Class inheritance

I'm relatively new to RoR and I'm having problem with NoMethodError.

So I'm doing this in rails console, I get this error message when I tried calling .create method. (Same thing with .save and .reload). I thought that those methods should be inherited from somewhere?

irb(main):001:0> User.create
NoMethodError: undefined method `create'
        from (irb):1
        from C:/RailsInstaller/Ruby1.9.2
/lib/rails/commands/console.rb:45:in `st
        from C:/RailsInstaller/Ruby1.9.2
/lib/rails/commands/console.rb:8:in `sta
        from C:/RailsInstaller/Ruby1.9.2
/lib/rails/commands.rb:40:in `<top (requ
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

Does anyone know the source of the problem? Thanks.

EDIT

User class is defined as:

class User < ActiveRecord::Base
   attr_accessible :name, :email
end

GEMFILE content is:

gem 'rails', '3.1.1'
gem 'sqlite3'
gem 'jquery-rails'

group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

group :test do
  gem 'turn', :require => false
end

Do you have a migration file to create users table under your /db/migrate ? If so, did you run rake db:migrate ? Make sure to start your console as rails console

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM