class admin < ActiveRecord::Base has_secure_password valIDates_uniqueness_of :email attr_accessible :email,:password,:password_confirmationend
According to the manual has_secure_password还添加了valIDates_confirmation_of:密码.如果我是正确的,如果:password和:password_confirmation不匹配,则valIDates_confirmation_of应始终出错 – 即使:password_confirmation为nil.
我正在使用RSpec进行测试,此测试失败并告诉我管理员是有效的:
admin = admin.newadmin.email = '[email protected]'admin.password = 'secret'admin.should be_invalID
这个通过:
admin = admin.newadmin.email = '[email protected]'admin.password = 'secret'admin.password_confirmation = ''admin.should be_invalID
那么,我做错了什么?
解决方法 这是has_secure_password的代码:# file activemodel/lib/active_model/secure_password.rb,line 32def has_secure_password attr_reader :password valIDates_confirmation_of :password valIDates_presence_of :password_digest include InstanceMethodsOnActivation if respond_to?(:attributes_protected_by_default) def self.attributes_protected_by_default super + ['password_digest'] end endend
如您所见,它永远不会确保发送密码确认.但是,您可以自己添加,只要页面上有表单字段,如果未填充,则会发送一个空字符串.
总结以上是内存溢出为你收集整理的ruby-on-rails – validates_confirmation_of:密码不会被触发全部内容,希望文章能够帮你解决ruby-on-rails – validates_confirmation_of:密码不会被触发所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)