NameError: variable o método local no definido `remember_digest y NoMethodError

Mi archivo user.rb consiste en

class User < ActiveRecord::Base attr_accessor :remember_token before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[az\d\-.]+\.[az]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } has_secure_password validates :password, presence: true, length: { minimum: 6 } # Returns the hash digest of the given string. def User.digest(string) cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost BCrypt::Password.create(string, cost: cost) end # Returns a random token. def User.new_token SecureRandom.urlsafe_base64 end # Remembers a user in the database for use in persistent sessions. def remember self.remember_token = User.new_token update_attribute(:remember_digest, User.digest(remember_token)) end # Forgets a user. def forget update_attribute(:remember_digest, nil) end # Returns true if the given token matches the digest. def authenticated?(remember_token) return false if remember_digest.nil? BCrypt::Password.new(remember_digest).is_password?(remember_token) end end 

me dan los errores

 ERROR["test_authenticated?_should_return_false_for_a_user_with_nil_digest", UserTest, 2015-06-01 21:01:42 +0000] test_authenticated?_should_return_false_for_a_user_with_nil_digest#UserTest (1433192502.88s) NameError: NameError: undefined local variable or method `remember_digest' for # app/models/user.rb:38:in `authenticated?' test/models/user_test.rb:70:in `block in ' app/models/user.rb:38:in `authenticated?' test/models/user_test.rb:70:in `block in ' ERROR["test_login_with_valid_information_followed_by_logout", UsersLoginTest, 2015-06-01 21:01:43 +0000] test_login_with_valid_information_followed_by_logout#UsersLoginTest (1433192503.06s) NoMethodError: NoMethodError: undefined method `remember_digest=' for # app/models/user.rb:28:in `remember' app/helpers/sessions_helper.rb:9:in `remember' app/controllers/sessions_controller.rb:9:in `create' test/integration/users_login_test.rb:22:in `block in ' app/models/user.rb:28:in `remember' app/helpers/sessions_helper.rb:9:in `remember' app/controllers/sessions_controller.rb:9:in `create' test/integration/users_login_test.rb:22:in `block in ' 22/22: [===================================================================================================================================================] 100% Time: 00:00:01, Time: 00:00:01 Finished in 1.38245s 22 tests, 42 assertions, 0 failures, 2 errors, 0 skips 

Tuve problemas similares. Es muy probable que no haya ejecutado las migraciones al principio del capítulo.

deberías estar bien si corres:

 $ rails generate migration add_remember_digest_to_users remember_digest:string 

seguido por

 $ bundle exec rake db:migrate