Validate groups of attributes

Hi, one of my models has a group of attributes that need to be in a
certain relationship to each other to be valid. So instead of validating
them individually I would like to validate them as a group, and, if
they are not valid, add one and only one error message to model.errors.
How can this be done? Thanks! Ingo

I found the answer. Here it in case this is useful for anybody:

class Rectangle < ActiveRecord::Base
def validate
unless self.left < self.right and self.top < self.bottom
self.errors.add(:bounds, ‘invalid bounds’)
end
end
end

what I didn’t know if that if an ActiveRecord model implements
‘validate’, that method is invoked on validation.

Ingo

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs