我正在阅读教程 运行代码清单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
问题/解决方案是什么?
答案 0 :(得分:1)
看起来你在Rails控制台内部执行了rails test:models
。
任何rails
或rake
命令都应在控制台之外执行,即执行rails console
的方式相同。