我正在尝试向 password
添加长度验证,但它总是出错并显示“密码太短”。
a = Artist.new(artist_name: 'Dylan', email: 'dylan@example.com', password: 'notshort')
p a.errors.full_messages # ["Password is too short (minimum is 6 characters)"]
a = Artist.new(artist_name: 'Dylan', email: 'dylan@example.com', password: 'short')
p a.errors.full_messages # ["Password is too short (minimum is 6 characters)"]
在我的模型中
has_secure_password
validates_length_of :password, minimum: 6
如果我将验证更改为
validates_length_of :password, minimum: 6, allow_blank: true
notshort
密码通过,但 short
也通过。
最佳答案
我也在使用 Bcrypt。这似乎对我有用:
has_secure_password
validates :password, length: { minimum: 6, maximum: 20 }, on: :create
关于ruby-on-rails - 密码长度验证永远不会通过 has_secure_password,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24767807/