Created
April 2, 2014 11:05
-
-
Save ahmetabdi/9932034 to your computer and use it in GitHub Desktop.
Validating Multiple Fields in Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate :unique_organisation_entry | |
def unique_organisation_entry | |
matched_entry = Organisation.where(['LOWER(name) = LOWER(?) AND LOWER(company_no) = LOWER(?) AND LOWER(postcode) = LOWER(?)', self.name, self.company_no, self.postcode]).first | |
errors.add(:base, 'I know you think you\'re clever, but someone already submitted that one.') if matched_entry && (matched_entry.id != self.id) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment