In Rails 3, how can I skip validation of the password field when I'm not attempting to update the password?

后端 未结 5 415
臣服心动
臣服心动 2020-12-05 10:31

My User model contains :name, :email, and :password fields. All 3 have validations for length. An \"update account\" web page allows the user to update his name and email

5条回答
  •  借酒劲吻你
    2020-12-05 11:19

    In your user model, you could just ignore the password validation if it's not set.

    validates_length_of :password, :minimum => N, :unless => lambda {|u| u.password.nil? }
    

提交回复
热议问题