我得到了上述错误,但不明白为什么。这是堆栈跟踪:
/Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/models/user.rb:8:in `<class:User>': undefined method `validates_confirmation_of' for User:Class (NoMethodError)
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/models/user.rb:4:in `<top (required)>'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/data_mapper_setup.rb:6:in `require_relative'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/data_mapper_setup.rb:6:in `<top (required)>'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/app.rb:4:in `require_relative'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/app/app.rb:4:in `<top (required)>'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/spec/spec_helper.rb:3:in `require'
from /Users/benrumble/Desktop/Apple_tv_movies_and_stuff/skeletons/Full_Stack_Sinatra_App_Skeleton/Skeleton_App_with_user_login:sign_up_and_bcrypt/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration.rb:1394:in `require'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration.rb:1394:in `block in requires='
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration.rb:1394:in `each'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration.rb:1394:in `requires='
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration_options.rb:111:in `each'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/configuration_options.rb:21:in `configure'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/runner.rb:99:in `setup'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/runner.rb:86:in `run'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/runner.rb:71:in `run'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/lib/rspec/core/runner.rb:45:in `invoke'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.0/exe/rspec:4:in `<top (required)>'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `load'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `<main>'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/benrumble/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
这是user.rb模型
require 'bcrypt'
require 'dm-validations'
class User
attr_reader :password
attr_accessor :password_confirmation
validates_confirmation_of :password
include DataMapper::Resource
property :id, Serial
property :email, String
property :password_digest, String, length: 60
def password=(password)
@password = password
self.password_digest = BCrypt::Password.create(password)
end
end
我尝试使用和不使用&d.d-validations&#39;但它并没有什么区别。
任何帮助都会很棒。
由于
答案 0 :(得分:0)
我通过移动
解决了这个问题include DataMapper::Resource
在宣布课程后作为第一行。