railstutorial.org, Chapter 6. unknown attribute: password

后端 未结 6 751
感动是毒
感动是毒 2021-01-05 14:11

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

6条回答
  •  时光取名叫无心
    2021-01-05 14:45

    I think the accepted answer, to add attr_accessor :password, :password_confirmation for User model is wrong. Because if has_secure_password creates those attributes virtually, that means it does it for some reason (security). So solution might be to invoke BCrypt wherever you create a User test object:

    require 'bcrypt'
    
        @user = User.new(name: 'test', password: BCrypt::Password.create("my password"), password_confirmation: 'my password')
    

    I wrote about this on this post:

    Rails - Unknown attribute password

    Please correct me if I am wrong.

提交回复
热议问题