Help with validation

Hi,

I’m trying to validate an array attribute
“accepts_nested_attributes_for”.
I’ve created a method like this:

validate :validate_nested_attributes

def validate_nested_attributes
items.each do |item|
errors.add(“item_#{item.number}_#{self.id}”, “error on
#{item.number}”) if item.value.blank?
end
end

But this method validates all items of array.
I just want do display erros one at a time instead displaying all erros
inside the form.

Tips on how to solve this problem ?

Thanks.

I don’t think you want your model validating another models attributes
like this but to answer the question you could put in a return
statement.
return errors.add(…)

Thanks.