Created
July 29, 2014 19:00
-
-
Save ejlangev/f67fadb4b5497d897452 to your computer and use it in GitHub Desktop.
Foreign Key Validator
This file contains 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
class ForeignKeyValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless value && value.to_s =~ /^\d+$/ && value.to_i > 0 | |
record.errors[attribute] << 'is not a valid foreign key' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍