Created
September 11, 2015 17:27
-
-
Save brianjlandau/b3d70497a914a69e7cac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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