Created
June 19, 2015 20:48
-
-
Save ajbeach2/8d3e884be0e0923fefa2 to your computer and use it in GitHub Desktop.
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 DomainValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless domain_check(value) | |
record.errors[attribute] << (options[:message] || "is not a valid domain") | |
end | |
end | |
def domain_check(name) | |
input = PublicSuffix.parse(name) | |
domain = input.domain | |
PublicSuffix.valid?(domain) | |
end | |
end | |
class Domain < ActiveRecord::Base | |
validates :name, uniqueness: true, domain: true, presence: true, length: { maximum: 50 } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment