title: Rails nested resources
body: <p>I'm trying to get my head around nested associations in Rails using ActiveResource.
  My example is as follows:
  What I have is an airport with many runways.</p>
  
  <p>My show action in airports controller contains:
      @airport = Airport.find(params[:id])</p>
  
  <p>When I call <a href="http://localhost/airports/2.xml" rel="nofollow noreferrer">http://localhost/airports/2.xml</a> I get that piece of XML:</p>
  
  <pre><code>&lt;airport&gt;
    &lt;code&gt;DUS&lt;/code&gt;
    &lt;created-at type="datetime"&gt;2009-02-12T09:39:22Z&lt;/created-at&gt;
    &lt;id type="integer"&gt;2&lt;/id&gt;
    &lt;name&gt;Duesseldorf&lt;/name&gt;
    &lt;updated-at type="datetime"&gt;2009-02-12T09:39:22Z&lt;/updated-at&gt;
  &lt;/airport&gt;
  </code></pre>
  
  <p>Now, I changed the action to </p>
  
  <pre><code>@airport = Airport.find(params[:id], :include =&gt; :runways)
  </code></pre>
  
  <p>How can I achieve that above loading above URL is giving me something like:</p>
  
  <pre><code>&lt;airport&gt;
    &lt;code&gt;FRA&lt;/code&gt;
    &lt;created-at type="datetime"&gt;2009-02-12T09:39:22Z&lt;/created-at&gt;
    &lt;id type="integer"&gt;2&lt;/id&gt;
    &lt;name&gt;Frankfurt&lt;/name&gt;
    &lt;updated-at type="datetime"&gt;2009-02-12T09:39:22Z&lt;/updated-at&gt;
  
    &lt;runways&gt;
      &lt;runway&gt;
        &lt;id&gt;1&lt;/id&gt;
        &lt;name&gt;bumpy runway&lt;/name&gt;
      &lt;/runway&gt;
    &lt;/runways&gt;
  
  &lt;/airport&gt;
  </code></pre>
  
  <p>And on top of that: If I have a client with</p>
  
  <pre><code>class Airport &lt; ActiveResource::Base
    ..
  end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Runway &lt; ActiveResource::Base
    ..
  end
  </code></pre>
  
  <p>How can I get it to automatically load associations like:</p>
  
  <pre><code>a = Airport.find(1)
  puts a.runways.length
  =&gt; 1
  </code></pre>
  
  <p>And (last but not least): Is there a way to store data from the client like:</p>
  
  <pre><code>a = Airport.find(1)
  a.runways &lt;&lt; Runway.find(1)
  a.save
  </code></pre>
  
  <p>Maybe I'm really too blind, but I'm stuck...
  Any idea is warmly welcome.</p>
  
  <p>Thanks</p>
  
  <p>Matt</p>