railstutorial.org, Chapter 6. unknown attribute: password

后端 未结 6 764
感动是毒
感动是毒 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:57

    I ended up spending a few hours and couldn't find any answers. My problem ended up being on the downcase line:

    before_save { self.email = email.downcase }
    

    He specifies that you can do this line in a different way which I did. See below.

    https://www.railstutorial.org/book/_single-page#sec-creating_and_authenticating_a_user

    In Listing 6.31, we could have written the assignment as self.email = self.email.downcase (where self refers to the current user), but inside the User model the self keyword is optional on the right-hand side: self.email = email.downcase

    Don't do it this way. It gave me error messages every time until I reverted to before_save { self.email = email.downcase }

    and removed: self.email = self.email.downcase

    I'm a noob so not completely sure why this made the difference but it did.

提交回复
热议问题