# Forms with nested objects

**URL:** <https://www.ruby-forum.com/t/forms-with-nested-objects/114497>\
**Category:** Rails\
**Created:** [September 13, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/forms-with-nested-objects/114497 "2007-09-13T13:34:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [September 13, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/forms-with-nested-objects/114497/1 "2007-09-13T13:34:48Z")

</div>

Hi,

I’m having a problem trying to create a form that can populated nested  
objects. In my main object, WG, I have two lists of objects: A objects,  
and  
B objects. I want to display a form where I can select an arbitrary  
number  
of A objects with checkboxes, and a single B object with radio buttons.  
The  
problem is that when I try to do a form for the WG object, I get hungup  
on  
what attributes to use in w.check\_box(). I’ve added a “selected”  
attribute  
to the A and B objects and was thinking I could use that, but when I do  
something like:

form\_for(:wg) do |w|  
w.a\_list.each do |a|  
w.check\_box(, {}, true,  
false)  
end  
end

I keep hitting nil objects and syntax errors.

Any ideas? Did I explain myself clear enough?

Thanks,  
Ryan

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [September 13, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/forms-with-nested-objects/114497/2 "2007-09-13T14:51:41Z")

</div>

> form\_for(:wg) do |w|  
> w.a\_list.each do |a|  
> w.check\_box(, {}, true,  
> false)  
> end  
> end
> 
> I keep hitting nil objects and syntax errors.
> 
> Any ideas? Did I explain myself clear enough?

use field\_for for the separate a & b objects then in the controller add  
them to each of their association collections of the wg object

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [September 17, 2007, 1:21pm UTC](https://www.ruby-forum.com/t/forms-with-nested-objects/114497/3 "2007-09-17T13:21:55Z")

</div>

That looks right. I searched around for field\_for which appears to be a  
typo. I found fields\_for, and an explanation of similar to what I’m  
trying  
to do here:

[http://railsforum.com/viewtopic.php?id=719](http://railsforum.com/viewtopic.php?id=719)

Thanks
