# Perplexing nested form issue

**URL:** <https://www.ruby-forum.com/t/perplexing-nested-form-issue/169240>\
**Category:** Rails\
**Created:** [June 1, 2009, 9:15am UTC](https://www.ruby-forum.com/t/perplexing-nested-form-issue/169240 "2009-06-01T09:15:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodoubtarockstar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a698b9/32.png) [@nodoubtarockstar](https://www.ruby-forum.com/u/nodoubtarockstar)\
**Post date:** [June 1, 2009, 9:15am UTC](https://www.ruby-forum.com/t/perplexing-nested-form-issue/169240/1 "2009-06-01T09:15:28Z")

</div>

Two apps, both running Rails 2.3.2, local machine, development  
environment, just to clarify that all gems are the same (obviously)  
and most of the code is “standard fare” — CRUD and such, nothing  
fancy going on.

Now that that’s out of the way, here’s the issue…

In both apps, I have objects which “belong\_to” another object, of  
which both have accepts\_nested\_attributes\_for said objects.

In both apps, in the form view for each particular object, I want to  
do multiple-child-object creation… So in other words, in App 1, I  
have loan\_applications. loan\_application has\_many :items – as such,  
an item belongs\_to :loan\_application

Thus I am able to generate 3 sets of “item fields” in the form so that  
a user can essentially create 3 items along with their application.

In App 2, I have products. Similarly, product has\_many :photos, :as  
=\> :owner, and therefore photo belongs\_to :owner, :polymorphic =\>  
true.

So, as you can see the only difference so far is the polymorphism.  
However, a photo also has\_attachment, since I am using attachment\_fu.

I am re-using the code that I wrote for the loan\_application items for  
the product photos. Fairly straightforward, right? Very similar  
assocation (just has\_many on both)… but the form output is  
completely different. The photos don’t output the proper id or name  
attributes on the file field. Take a look at the pastie below, you  
will see very very few differences between the two (in fact they are  
differences I already pointed out, polymorphism and attachment\_fu).

[http://pastie.org/496243](http://pastie.org/496243)

So my thought is, maybe nested fields\_for hasn’t come far enough for  
polymorphic associations? That just seems quite odd…

Any thoughts/feedback/musings welcome, I’d love to get this figured  
out so that I can continue on to bigger-better problem-solving 🙂

Cheers!
