Skip to content

Instantly share code, notes, and snippets.

@chewmanfoo
chewmanfoo / url_validator.rb
Created October 12, 2012 20:36 — forked from bluemont/url_validator.rb
ActiveModel URL Validator
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")