title: Creating nested association records Ruby on Rails
body: <p>Apparently I am overlooking something very simple in the example I have done below where I am attempting to create nested association records while instantiating a new parent record.</p>
  
  <p>I'm hoping a fresh set of eyes my help find what has been eating at me for days. Thanks in advance!
  What am I missing/messing up? It seems so trivial.</p>
  
  <p>ActiveRecord::NestedAttributes is obviously unhappy.</p>
  
  <pre><code>class ContentGroup &lt; ActiveRecord::Base
    attr_protected
  
    has_many :contents, :dependent=&gt;:destroy
  
    accepts_nested_attributes_for :contents
  end
  </code></pre>
  
  <hr>
  
  <pre><code>class Content &lt; ActiveRecord::Base 
    attr_protected
  
    has_one :sort_item, :as=&gt;:sortable
    belongs_to :content_group, :dependent=&gt;:destroy
  
   accepts_nested_attributes_for :sort_item
  end
  </code></pre>
  
  <hr>
  
  <pre><code>class SortItem &lt; ActiveRecord::Base
    attr_accessible :position, :sortable_id, :sortable_type
    belongs_to :sortable, :polymorphic=&gt;true
  end
  </code></pre>
  
  <hr>
  
  <h1>in rails console, lightly nested call works as expected:</h1>
  
  <pre><code>&gt; p = {"sort_item_attributes"=&gt;{"position"=&gt;"1"}}
  &gt; b = Content.new(p)
   =&gt; Content id: nil, content_group_id: nil
  </code></pre>
  
  <h1>one additional nest blows up:</h1>
  
  <pre><code>&gt; p = {"contents_attributes"=&gt;{"sort_item_attributes"=&gt;{"position"=&gt;"1"}}}
  &gt; cg = ContentGroup.new(p)
  
   ActiveRecord::UnknownAttributeError: unknown attribute: position
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/reflection.rb:183:in `new'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/reflection.rb:183:in `build_association'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:233:in `build_record'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:112:in `build'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/nested_attributes.rb:406:in `block in assign_nested_attributes_for_collection_association'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/nested_attributes.rb:401:in `each'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/nested_attributes.rb:401:in `assign_nested_attributes_for_collection_association'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/nested_attributes.rb:289:in `contents_attributes='
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:94:in `block in assign_attributes'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:93:in `each'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:93:in `assign_attributes'
      from /.rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
      from (irb):10:in `new'
      from (irb):10
      from /.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
      from /.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
      from /.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:41:in `&lt;top (required)&gt;'
      from script/rails:6:in `require'
  </code></pre>
  
  <p>Hope this can be fixed, sorry if there's an obvious mistake on my part.</p>