title: How do I find a child's parent through a has_one association in Rails3?
body: <p>Say I have the following models:</p>
  
  <pre><code>class Parent &lt; ActiveRecord::Base
    has_one :child
  end
  
  class Child &lt; ActiveRecord::Base
    belongs_to :parent
  end
  </code></pre>
  
  <p>I'd like to retrive the parent through the child, but doing the following fails:
  I find the model in the following way through a controller</p>
  
  <pre><code>@child = Child.find(params[:child_id])
  </code></pre>
  
  <p>(Not sure if this is relevant, but since I'm using shallow routing, the parent_id is not available in the URL)</p>
  
  <p>In my view, I'd like to retrieve the child's parent like this:</p>
  
  <pre><code>@child.parent
  </code></pre>
  
  <p>How would I go about doing this?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>Update: my example (when I decided to start a new app and create it) actually ran perfectly.
  In my actual app, I forgot to include <code>belongs_to :parent</code> in the child's model. How silly of me. Thanks for taking the time to comment and answer, guys. Next time I'll look more carefully before posting a question here.</p>