How do I validate that two values do not equal each other in a Rails model?

前端 未结 9 1668
既然无缘
既然无缘 2020-12-29 20:31

I have a User model, which has an email and a password field. For security, these may not be equal to each other. How can I define this in my model?

9条回答
  •  不知归路
    2020-12-29 21:21

    By using custom validations we can do this operation

    validate :validate_address

    def validate_address
    errors.add(:permenent_address, "can't be the same as present_address") if self.present_address== self.permenent_address end

提交回复
热议问题