railstutorial.org,第 6 章.未知属性:密码 [英] railstutorial.org, Chapter 6. unknown attribute: password

查看:33
本文介绍了railstutorial.org,第 6 章.未知属性:密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了第 6 章 railstutorial 但我所有的 用户模型规范 在我添加 后不久就开始失败密码 &password_confirmation 有以下错误:

I have finished Chapter 6 of railstutorial but all my User model specs have started failing soon after I added password & password_confirmation with the following errors:

Failures:

  1) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  2) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  3) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  4) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  5) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  6) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  7) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  8) User when name is not present 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  9) User when email is not present 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  10) User when name is too long 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  11) User when email format is invalid should be invalid
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  12) User when email format is valid should be valid
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  13) User when email address is already taken 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  14) User when password is not present 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  15) User when password confirmation is nil 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  16) User when password doesn't match confirmation 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  17) User return value of authenticate method with valid password 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  18) User return value of authenticate method with invalid password 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  19) User return value of authenticate method with invalid password 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  20) User with a password that's too short 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com",
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:17:in `new'
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

Finished in 7.43 seconds
39 examples, 20 failures, 5 pending

Failed examples:

rspec ./spec/models/user_spec.rb:22 # User 
rspec ./spec/models/user_spec.rb:23 # User 
rspec ./spec/models/user_spec.rb:24 # User 
rspec ./spec/models/user_spec.rb:25 # User 
rspec ./spec/models/user_spec.rb:26 # User 
rspec ./spec/models/user_spec.rb:27 # User 
rspec ./spec/models/user_spec.rb:28 # User 
rspec ./spec/models/user_spec.rb:32 # User when name is not present 
rspec ./spec/models/user_spec.rb:37 # User when email is not present 
rspec ./spec/models/user_spec.rb:42 # User when name is too long 
rspec ./spec/models/user_spec.rb:46 # User when email format is invalid should be invalid
rspec ./spec/models/user_spec.rb:57 # User when email format is valid should be valid
rspec ./spec/models/user_spec.rb:73 # User when email address is already taken 
rspec ./spec/models/user_spec.rb:78 # User when password is not present 
rspec ./spec/models/user_spec.rb:83 # User when password confirmation is nil 
rspec ./spec/models/user_spec.rb:88 # User when password doesn't match confirmation 
rspec ./spec/models/user_spec.rb:96 # User return value of authenticate method with valid password 
rspec ./spec/models/user_spec.rb:102 # User return value of authenticate method with invalid password 
rspec ./spec/models/user_spec.rb:103 # User return value of authenticate method with invalid password 
rspec ./spec/models/user_spec.rb:109 # User with a password that's too short 
rake aborted!

可以在此处找到用户模型 现在,我已经将源与原始进行了比较,但似乎我遗漏了一些东西.不要这样

The User Model can be found here Now, I have already compared the source to original but it seems I am missing something. Don't what it is

谁能告诉我为什么会出现这个错误?

Can anyone tell me why this error is coming?

推荐答案

添加:

attr_accessor :password, :password_confirmation

然后本教程会让你在 password_digest

这篇关于railstutorial.org,第 6 章.未知属性:密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆