Yes, use the method validates_each
serialize :urls
validates_each :urls do |record, attr, value|
problems = ''
if value
value.each{|name_url|
problems << "Name #{name_url['name']} is missing its url. " \
unless name_url['url']}
else
problems = 'Please supply at least one name and url'
end
record.errors.add(:urls, problems) unless problems.empty?
end
Added: you cannot use validations such as validates_length_ofsince the validation method does not understand the format of your serialized field.
The method validates_eachis good, as it allows you to write your own verification method. Then the method can add an error to the record, if necessary.
. :base record.errors, . .