Skip to content

Instantly share code, notes, and snippets.

Avatar

Sathish Manohar sathishmanohar

View GitHub Profile
@bluemont
bluemont / url_validator.rb
Created Jun 25, 2012
ActiveModel URL Validator
View url_validator.rb
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")