# Should fields\_for for has\_many association execute block even if the collection is empty?

**URL:** <https://www.ruby-forum.com/t/should-fields-for-for-has-many-association-execute-block-even-if-the-collection-is-empty/176113>\
**Category:** Rails\
**Created:** [September 24, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/should-fields-for-for-has-many-association-execute-block-even-if-the-collection-is-empty/176113 "2009-09-24T22:50:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [September 24, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/should-fields-for-for-has-many-association-execute-block-even-if-the-collection-is-empty/176113/1 "2009-09-24T22:50:24Z")

</div>

Hi,

I had a problem where fields\_for block was executed once, even if the  
association collection was empty - child\_form.object was nil of  
course. Adding accepts\_nested\_attributes to parent model solved the  
problem - block is now executed correctly for each instance of the  
collection.

Is this proper behavior or a bug? I’m using Rails 2.3.4

Cheers,  
Szymek
