Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'uri'
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.present?
begin
unless URI(value).is_a?(URI::HTTP)
record.errors.add(attribute, :invalid_uri, options)
end
rescue
record.errors.add(attribute, :invalid_uri, options)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.