title: Rails can't save a nested resource via ActiveResource
body: <p>I'm having a problem using ActiveResource to save a model with a nested resource: I can load and save a non-nested resource with no problems, and I can load a resource plus its nested resources fine, but saving the resource fails. This problem occurs for me with REE 1.8.7/Rails 2.3.9 and Ruby 1.9.2-p0/Rails 3.0.2. The examples below are from Rails 3/AR 3.</p>
  
  <p>There are two models in my sample app:</p>
  
  <ul>
  <li>Asset</li>
  <li>Interface</li>
  </ul>
  
  <p>Assets have many Interfaces, Interfaces belong to Assets.</p>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>Rails3Testapp::Application.routes.draw do
   resources :interfaces
   resources :assets
  end
  </code></pre>
  
  <p><strong>Relevant AssetController actions</strong></p>
  
  <pre><code>  def index
      @assets = Asset.all
  
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml =&gt; @assets, :include =&gt; [ :interfaces ] }
      end
    end
  
    def show
      @asset = Asset.find(params[:id])
  
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @asset, :include =&gt; [ :interfaces ] }
      end
    end
  
    def update
      @asset = Asset.find(params[:id])
  
      respond_to do |format|
        if @asset.update_attributes(params[:asset])
          format.html { redirect_to(@asset, :notice =&gt; 'Asset was successfully updated.') }
          format.xml  { head :ok }
        else
          format.html { render :action =&gt; "edit" }
          format.xml  { render :xml =&gt; @asset.errors, :status =&gt; :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Asset &lt; ActiveRecord::Base
    has_many :interfaces
  
    accepts_nested_attributes_for :interfaces
  end
  
  class Interface &lt; ActiveRecord::Base
    belongs_to :asset
  end
  </code></pre>
  
  <p><strong>Steps to Replicate</strong></p>
  
  <pre><code>&gt;&gt; require 'active_resource'
  =&gt; true
  &gt;&gt; class Asset &lt; ActiveResource::Base
  &gt;&gt;   self.site = 'http://localhost:3000/'
  &gt;&gt; end
  &gt;&gt; test_asset = Asset.first
  =&gt; #&lt;Asset:0x00000100a86690 @attributes={"created_at"=&gt;2010-12-07 16:24:59 UTC, "description"=&gt;"Testing testing", "id"=&gt;1, "name"=&gt;"Test Asset #1", "updated_at"=&gt;2010-12-07 16:24:59 UTC, "interfaces"=&gt;[#&lt;Asset::Interface:0x00000100a7dc98 @attributes={"asset_id"=&gt;1, "created_at"=&gt;2010-12-07 18:01:15 UTC, "id"=&gt;1, "name"=&gt;"eth0", "updated_at"=&gt;2010-12-07 18:01:15 UTC}, @prefix_options={}&gt;, #&lt;Asset::Interface:0x00000100a7a8e0 @attributes={"asset_id"=&gt;1, "created_at"=&gt;2010-12-07 18:04:49 UTC, "id"=&gt;2, "name"=&gt;"eth1", "updated_at"=&gt;2010-12-07 18:04:49 UTC}, @prefix_options={}&gt;]}, @prefix_options={}&gt;
  &gt;&gt; test_asset.save
  ActiveResource::ServerError: Failed.  Response code = 500.  Response message = Internal Server Error .
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/connection.rb:147:in `handle_response'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/connection.rb:114:in `request'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/connection.rb:91:in `block in put'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/connection.rb:217:in `with_auth'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/connection.rb:91:in `put'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/base.rb:1307:in `update'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/observing.rb:11:in `update_with_notifications'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/base.rb:1117:in `save'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/validations.rb:87:in `save_with_validation'
      from /Users/threetee/.rvm/gems/ruby-1.9.2-p0@rails3/gems/activeresource-3.0.3/lib/active_resource/observing.rb:11:in `save_with_notifications'
      from (irb):33
      from /Users/threetee/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `&lt;main&gt;'
  </code></pre>
  
  <p><strong>Log</strong></p>
  
  <pre><code>Started PUT "/assets/1.xml" for 127.0.0.1 at 2010-12-07 11:58:40 -0800
    Processing by AssetsController#update as XML
    Parameters: {"asset"=&gt;{"created_at"=&gt;2010-12-07 16:24:59 UTC, "description"=&gt;"Testing testing", "id"=&gt;1, "name"=&gt;"Test Asset #1", "updated_at"=&gt;2010-12-07 16:24:59 UTC, "interfaces"=&gt;[{"asset_id"=&gt;1, "created_at"=&gt;2010-12-07 18:01:15 UTC, "id"=&gt;1, "name"=&gt;"eth0", "updated_at"=&gt;2010-12-07 18:01:15 UTC}, {"asset_id"=&gt;1, "created_at"=&gt;2010-12-07 18:04:49 UTC, "id"=&gt;2, "name"=&gt;"eth1", "updated_at"=&gt;2010-12-07 18:04:49 UTC}]}, "id"=&gt;"1"}
    SQL (0.8ms)   SELECT name
   FROM sqlite_master
   WHERE type = 'table' AND NOT name = 'sqlite_sequence'
  
    Asset Load (0.2ms)  SELECT "assets".* FROM "assets" WHERE ("assets"."id" = 1) LIMIT 1
  WARNING: Can't mass-assign protected attributes: id
  Completed   in 161ms
  
  ActiveRecord::AssociationTypeMismatch (Interface(#2154409400) expected, got ActiveSupport::HashWithIndifferentAccess(#2154546040)):
    app/controllers/assets_controller.rb:62:in `block in update'
    app/controllers/assets_controller.rb:61:in `update'
  </code></pre>
  
  <p>Anybody have any ideas on this one? I'm stumped. Thanks in advance for any help!</p>