# Complex form validation problem

**URL:** <https://www.ruby-forum.com/t/complex-form-validation-problem/176768>\
**Category:** Rails\
**Created:** [October 6, 2009, 1:50am UTC](https://www.ruby-forum.com/t/complex-form-validation-problem/176768 "2009-10-06T01:50:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fahrio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e68b1a/32.png) [@fahrio](https://www.ruby-forum.com/u/fahrio)\
**Post date:** [October 6, 2009, 1:50am UTC](https://www.ruby-forum.com/t/complex-form-validation-problem/176768/1 "2009-10-06T01:50:52Z")

</div>

I have a complex form for my Work model. It accepts nested attributes  
for Credits, Images and Videos. (it is a modified version of Eloy  
Duran’s complex form example)

I want to validate presence of at least one Credit  
I want to validate presence of at least one Image or one Video

When I do (in work.rb):  
validates\_presence\_of :credits  
It validates properly when I try to submit the form without any  
credits but it does not validate if I remove the last credit (by  
checking a check\_box that adds “\_delete” to credit’s attributes). It  
submits the work deleting the one and only credit leaving the work  
without any credits.

If I could find a way to check if last credit is selected for deletion  
from the Work model I coult prevent the save but feels like the wrong  
way, trying to access credits attributes from the work model.

Do you have any idea on how I can validate these properly?

Thanks

---

<div class="post-metadata">

**Author:** ![fahrio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e68b1a/32.png) [@fahrio](https://www.ruby-forum.com/u/fahrio)\
**Post date:** [October 6, 2009, 10:23am UTC](https://www.ruby-forum.com/t/complex-form-validation-problem/176768/2 "2009-10-06T10:23:08Z")

</div>

I have got this answered on  
[Rails Complex Form Validations? - Stack Overflow](http://stackoverflow.com/questions/1521028/rails-complex-form-validations).
