Skip to content

Instantly share code, notes, and snippets.

@viruthagiri
Forked from bluemont/url_validator.rb
Created March 14, 2014 18:47
Show Gist options
  • Save viruthagiri/9554173 to your computer and use it in GitHub Desktop.
Save viruthagiri/9554173 to your computer and use it in GitHub Desktop.
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = begin
URI.parse(value).kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
unless valid
record.errors[attribute] << (options[:message] || "is an invalid URL")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment