rails test:RailsTutorials中的模型错误,第6章

时间:2017-06-01 23:39:16

标签: ruby-on-rails

我正在阅读教程 运行代码清单6.6中的代码时,https://www.railstutorial.org/book/modeling_users和第6章遇到了问题,例如

rails test:models

在控制台中我收到错误

NameError: undefined local variable or method `models' for main:Object.

我尝试了类似的结果:

2.3.0 :010 >  @user = User.new(name: "Example User", email: 
"user@example.com")
=> #<User id: nil, name: "Example User", email: "user@example.com", 
created_at: nil, updated_at: nil, password_digest: nil, 
remember_digest: nil, admin: false, activation_digest: nil, activated: 
false, activated_at: nil, reset_digest: nil, reset_sent_at: nil> 
2.3.0 :011 > @user.name
=> "Example User" 
2.3.0 :012 > @user.email
=> "user@example.com" 
2.3.0 :013 > @user.valid?
=> true 

2.3.0 :016 > NameError: undefined local variable or method `models' for 
main:Object

问题/解决方案是什么?

1 个答案:

答案 0 :(得分:1)

看起来你在Rails控制台内部执行了rails test:models

任何railsrake命令都应在控制台之外执行,即执行rails console的方式相同。