Rails URL Validation
1 2 validates_each :href, :on => :create do |record, attr, value| 3 begin 4 uri = URI.parse(value) 5 if uri.class != URI::HTTP 6 record.errors.add(attr, 'Only HTTP protocol addresses can be used') 7 end 8 rescue URI::InvalidURIError 9 record.errors.add(attr, 'The format of the url is not valid.') 10 end 11 end