WIA/lib/url_validator.rb

13 lines
343 B
Ruby
Raw Normal View History

2012-05-03 01:25:26 -04:00
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
uri = URI.parse(value)
resp = uri.kind_of?(URI::HTTP)
rescue URI::InvalidURIError
resp = false
end
unless resp == true
record.errors[attribute] << (options[:message] || "is not an url")
end
end
end