# How do you use form helpers with nested objects?

**URL:** <https://www.ruby-forum.com/t/how-do-you-use-form-helpers-with-nested-objects/118063>\
**Category:** Rails\
**Created:** [October 23, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/how-do-you-use-form-helpers-with-nested-objects/118063 "2007-10-23T18:04:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avramd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@avramd](https://www.ruby-forum.com/u/avramd)\
**Post date:** [October 23, 2007, 6:04pm UTC](https://www.ruby-forum.com/t/how-do-you-use-form-helpers-with-nested-objects/118063/1 "2007-10-23T18:04:08Z")

</div>

Hello,

I have a form which contains a table that users fill in. The table data  
will not be going into the form’s own object, but into a series of  
objects (one per row) via a has\_man :through relationship.

I can’t figure out how to supply field names to the form helper methods  
so that the proper params sub-hashes will be built. I’m currently  
building the form fields manually, and this is what they look like:

```
 <input id="inclusion_1_fee" name="inclusion[1][fee]" size="4"

```

type=“text”/\>

Would someone please tell me how I can generate these input tags using a  
form helper method?

Thanks,  
Avram

---

<div class="post-metadata">

**Author:** ![avramd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@avramd](https://www.ruby-forum.com/u/avramd)\
**Post date:** [October 26, 2007, 9:17am UTC](https://www.ruby-forum.com/t/how-do-you-use-form-helpers-with-nested-objects/118063/2 "2007-10-26T09:17:21Z")

</div>

To anyone who cares, I found the answer here:

[http://railsforum.com/viewtopic.php?pid=3714](http://railsforum.com/viewtopic.php?pid=3714)

The short version is that fields\_for somehow does this automagically. I  
don’t really understand how it works, it appears to involve what I  
consider a trick, whereby you make sure you have an instance variable  
around who’s name matches the value you supply to fields\_for, and then  
it inserts that object’s .id attribute into the []. I don’t really know,  
I’m just guessing from looking at the code.
