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 SubdomainValidator < ActiveModel::EachValidator | |
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator | |
def validate_each(object, attribute, value) | |
return unless value.present? | |
reserved_names = %w(www ftp mail pop smtp admin ssl sftp) | |
reserved_names = options[:reserved] if options[:reserved] | |
if reserved_names.include?(value) | |
object.errors[attribute] << 'cannot be a reserved name' | |
end |