Skip to content

Instantly share code, notes, and snippets.

@brianjlandau
Created September 11, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianjlandau/b3d70497a914a69e7cac to your computer and use it in GitHub Desktop.
Save brianjlandau/b3d70497a914a69e7cac to your computer and use it in GitHub Desktop.
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