class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /https?:\/\/[-a-zA-Z0-9@:%_\+.~#?&\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/=]*)?/
record.errors[attribute] << (options[:message] || "is not a valid URL")
end
end
end