# Polymorphic Nested Attributes In 2.3

**URL:** <https://www.ruby-forum.com/t/polymorphic-nested-attributes-in-2-3/162241>\
**Category:** Rails\
**Created:** [March 7, 2009, 11:54am UTC](https://www.ruby-forum.com/t/polymorphic-nested-attributes-in-2-3/162241 "2009-03-07T11:54:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Taylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@Gary\_Taylor](https://www.ruby-forum.com/u/Gary_Taylor)\
**Post date:** [March 7, 2009, 11:54am UTC](https://www.ruby-forum.com/t/polymorphic-nested-attributes-in-2-3/162241/1 "2009-03-07T11:54:42Z")

</div>

Has anyone had any experience of using nested attributes with  
polymorphic associations ? I cannot see how it would work as the  
model would need to know the class of the object to create (when  
creating a new record for the association).

Here is an example

class MyClass \< ActiveRecord::Base  
belongs\_to :owner, :polymorphic=\>true  
accepts\_nested\_attributes\_for :owner  
end

This generates a method called ‘owner\_attributes=’ which is fair  
enough, but it does not generate the method ‘build\_owner’ which is  
required by the looks of it.

So, if I try using owner\_attributes=, then straight away it complains  
that the method build\_owner is missing.

Regards

Gary Taylor

---

<div class="post-metadata">

**Author:** ![Gary\_Taylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@Gary\_Taylor](https://www.ruby-forum.com/u/Gary_Taylor)\
**Post date:** [March 12, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/polymorphic-nested-attributes-in-2-3/162241/2 "2009-03-12T20:14:34Z")

</div>

If MyClass belongs to your :owner model, wouldn’t the :owner model be  
the one that accepts nested attributes for MyClass?
