Forum: Ruby on Rails Polymorphic Nested Attributes In 2.3

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gary Taylor (Guest)
on 2009-03-07 12:54
(Received via mailing list)
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

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.


Gary Taylor
Lee S. (Guest)
on 2009-03-12 21:14
If MyClass belongs to your :owner model, wouldn't the :owner model be
the one that accepts nested attributes for MyClass?
This topic is locked and can not be replied to.