Rails Tutorial (Hartl) Error - Section 7 - "unkown attribute: password"

I looked for this problem in the forum and used the solution on the spork website to remove the "-drb" from the specification options, got it to load and run, and this constant error continues to appear. I also run it without spork. I read ahead on a bunch of rspec information and, as I said, dug out information about spork, but so far nothing. I also ran typo checks, indentation, coding ... and I'm still at a loss. Other problems, I could fix, but this one got me. Here below if anyone has a suggestion:

Failures:

1) Has_password user password encryption? the method must be false if the passwords do not match Error / Error: @user = User.create! (@Attr) ActiveRecord :: UnknownAttributeError: Unknown attribute: password #. / Spec / models / user_spec.rb: 94: in `block (3 levels) in '

Finished by 0.836 seconds 1 example, 1 failure <- Slave (1) is running!

+4
source share
3 answers

Are you sure you added: password as a virtual attribute in your user model? Easy to skip, but you need to include the line

attr_accessor :password 
+8
source

Perhaps this has changed between how the question was asked (2011), and now, but at the beginning I faced the same problem - I added all the tests for the password, etc., and the user initialization itself was otherwise using " unknown attribute: password. "

At first glance, GrahamJRoy's answer (and, more importantly, the subsequent development comment) fully satisfied my confusion.

However, I continued to read the next section of the tutorial and found out that the next line in the User model implies the same thing:

 has_secure_password 

Once I added this, I no longer need an explicit attr_accessor declaration:

 attr_accessor :password, :password_confirmation 

My only complaint in this tutorial is that Michael does not warn you that ALL of your user links will fail if you add the password: and password_confirmation in User.new () when you are in the tutorial see the updated constructor. I expected that only new tests would fail, thought that I was disconnected, and therefore looked in another place (for example, here) for a solution before continuing the tutorial.

0
source

Be sure to change attr_accessible to attr_accessor in models/user.rb

I made the same mistake and skipped it.

0
source

Source: https://habr.com/ru/post/1345585/


All Articles