ruby 代码
- validates_each :href, :on => :create do |record, attr, value|
- begin
- uri = URI.parse(value)
- if uri.class != URI::HTTP
- record.errors.add(attr, 'Only HTTP protocol addresses can be used')
- end
- rescue URI::InvalidURIError
- record.errors.add(attr, 'The format of the url is not valid.')
- end
- end