# Validation on nested models

**URL:** <https://www.ruby-forum.com/t/validation-on-nested-models/189471>\
**Category:** Rails\
**Created:** [June 1, 2010, 2:49pm UTC](https://www.ruby-forum.com/t/validation-on-nested-models/189471 "2010-06-01T14:49:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 1, 2010, 2:49pm UTC](https://www.ruby-forum.com/t/validation-on-nested-models/189471/1 "2010-06-01T14:49:53Z")

</div>

this validation in my model only works for the first nested model.  
Why is that?

def treatment\_must\_have\_preptype  
errors.add(:preptype,  
I18n.translate(‘activerecord.errors.messages.nestedTrempty’)) if  
treatment\_preptype\_empty?  
end

def treatment\_preptype\_empty?  
if !treatments.empty?  
treatments.all? {|treatment| treatment[‘preptype’].blank? }  
end  
end
