title: Get parent attribute within new child form?
body: <p>I have a simple Rails 3 application and I am trying to create a new record that belongs to it's owner. It's working by passing the id to a hidden field in the new form of the child record.</p>
  
  <p>This works well and once the new child form submitted it correctly gets associated in the child/parent relationship.</p>
  
  <p>What I am trying to do, is lookup values form the parent within the new child form. The problem is that the child relationship is not yet created. Is there anyway I can use a .where lookup in the view? Or, is there a better way of doing this?</p>
  
  <p>At the moment I am passing the animal_id though to the new Claim form and it's inserted into a hidden field labelled animal_id.</p>
  
  <p>What I am trying to do:</p>
  
  <pre><code>&lt;%= @animal.where(:animal_id =&gt; params[:animal_id]).id %&gt;
  </code></pre>
  
  <p>The above would ideally get the animal ID from the soon-to-be-associated animal. Is there any sort of before_filter or anything that could take the passed params from the URL and temporarily create the relationship just for the new form view and then permanently create the relationship once the form is submitted?</p>
  
  <p>I've tried adding the following to my Claims controller and then called <code>@animal.AnimalName</code> in the view but I get NoMethodError:</p>
  
  <pre><code>before_filter :find_animal
  
  protected
  def find_animal
   if params[:animal_id]
     Animal.find(params[:animal_id])
   end
  end
  </code></pre>
  
  <p>The URL of the new claim is correctly showing the animal ID so I'm not sure why it's not finding it:</p>
  
  <pre><code>http://localhost:3000/claims/new?animal_id=1
  </code></pre>
  
  <p>The model relations are as follows:</p>
  
  <pre><code>animal has_many claims
  animal has_one exclusion
  
  claim has_one animal
  
  exclusion has_one animal
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I've corrected my relationships to as follows:</p>
  
  <pre><code>animal has_one exclusion
  exclusions belong_to animal
  </code></pre>