Ruby on Rails Password Validation

前端 未结 4 781
鱼传尺愫
鱼传尺愫 2020-12-29 08:16

So I have interesting password validation requirements:

  • When a user signs up, I want them to have to type in password and confirm and be between 6..4

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 08:42

    this works for blank password on update action:

    validates :password, :presence => true, :on => :update,
     :if => lambda{ !password.nil? }
    
    validates :password,
      :confirmation => true,
      :length => { :minimum => 6},
      :if => lambda{ new_record? || !password.nil? }
    

提交回复
热议问题