How do you use form helpers with nested objects?


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"


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


To anyone who cares, I found the answer here:

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.