# Reject a nested object if all parameters of its own nested object are blank

**URL:** <https://www.ruby-forum.com/t/reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188203>\
**Category:** Rails\
**Created:** [May 7, 2010, 3:36pm UTC](https://www.ruby-forum.com/t/reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188203 "2010-05-07T15:36:55Z")\
**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:** [May 7, 2010, 3:36pm UTC](https://www.ruby-forum.com/t/reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188203/1 "2010-05-07T15:36:55Z")

</div>

Hello,

I have a model called Sample that has many Treatments. A Treatment  
can have many Results.

I want to reject the creation of a Treatment if all its fields are  
blank and if all the fields of each of its nested Results are blank.

I have this in the Sample model:

accepts\_nested\_attributes\_for :treatments, :allow\_destroy =\>  
true, :reject\_if =\> proc { |attributes|  
attributes[‘treatmenttype’].blank? && attributes[‘author’].blank? &&  
attributes[‘results\_attributes’].blank? }

This part:  
attributes[‘results\_attributes’].blank?

only makes it reject the Treatment if there are no Results, but how  
can I write the conditions so that it will reject the creation of a  
Treatment if all the attirubtes of each Result are blank? Right now  
it creates the Treatment if the Result exists, regardless of whether  
all its fields are blank.
