Can nested attributes be used in combination with inheritance?
Posted
by FoxDemon
on Stack Overflow
See other posts from Stack Overflow
or by FoxDemon
Published on 2010-03-31T14:50:44Z
Indexed on
2010/03/31
14:53 UTC
Read the original article
Hit count: 385
I have the following classes:
Project
Person
Person > Developer
Person > Manager
In the Project model I have added the following statements:
has_and_belongs_to_many :people
accepts_nested_attributes_for :people
And of course the appropriate statements in the class Person. How can I add an Developer to a Project through the nested_attributes method? The following does not work:
@p.people_attributes = [{:name => "Epic Beard Man", :type => "Developer"}]
@p.people
=> [#<Person id: nil, name: "Epic Beard Man", type: nil>]
As you can see the type attributes is set to nil instead of Developer.
© Stack Overflow or respective owner