简体   繁体   English

Ruby on Rails:类继承的未定义方法

[英]Ruby on Rails: undefined method for Class inheritance

I'm relatively new to RoR and I'm having problem with NoMethodError. 我对RoR比较陌生,但遇到NoMethodError问题。

So I'm doing this in rails console, I get this error message when I tried calling .create method. 因此,我在Rails控制台中执行此操作,尝试调用.create方法时收到此错误消息。 (Same thing with .save and .reload). (与.save和.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: GEMFILE的内容是:

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 ? /db/migrate下,您是否有一个迁移文件来创建users表? If so, did you run rake db:migrate ? 如果是这样,您是否运行过rake db:migrate Make sure to start your console as rails console 确保将控制台启动为rails console

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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