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

**URL:** <https://www.ruby-forum.com/t/re-reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188248>\
**Category:** Rails\
**Created:** [May 8, 2010, 11:20am UTC](https://www.ruby-forum.com/t/re-reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188248 "2010-05-08T11:20:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fattah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@Fattah](https://www.ruby-forum.com/u/Fattah)\
**Post date:** [May 8, 2010, 11:20am UTC](https://www.ruby-forum.com/t/re-reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188248/1 "2010-05-08T11:20:27Z")

</div>

You can write method to validate nested result attributes.

Def valid\_nested\_results?(results\_attributes)

results\_attributes.each do|res\_attr|  
return false if(res\_attr[‘attr1’].blank? and res\_attr[‘attr2’].blank?  
…)  
end

return true

end

And use this method in reject\_if instead of  
attributes[‘results\_attributes’].blank?

Or you can also define the appropriate :reject\_if for nested attribute  
definition for results in treatment model.

Does it help?

---

<div class="post-metadata">

**Author:** ![Fattah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7cd45c/32.png) [@Fattah](https://www.ruby-forum.com/u/Fattah)\
**Post date:** [May 11, 2010, 7:26pm UTC](https://www.ruby-forum.com/t/re-reject-a-nested-object-if-all-parameters-of-its-own-nested-object-are-blank/188248/2 "2010-05-11T19:26:44Z")

</div>

oh, it works if you reject the creation of the third-level nested  
model in the second-level nested model.
