我正在尝试向 中添加长度验证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
.