title: Nested Attributes in Rails 3
body: <p>can anyone please walk me through Nested Attributes in Rails 3?</p>
  
  <p>I have two Models: Certificates and Custodians, related as follows:</p>
  
  <p>Certificate Model:</p>
  
  <pre><code>class Certificate &lt; ActiveRecord::Base
    belongs_to :shareholder
    belongs_to :custodian
    belongs_to :issuer
  
    accepts_nested_attributes_for :custodian, :shareholder, :issuer 
  end
  </code></pre>
  
  <p>Certificate Controller:</p>
  
  <pre><code>class CertificateController &lt; ApplicationController
    def issue
      @certificate = Certificate.new
      @certificate.custodian.build
    end
  end
  </code></pre>
  
  <p>My View:</p>
  
  <pre><code>&lt;% form_for(:certificate, :url =&gt; {:action =&gt; 'testing'}) do |f| -%&gt;
  
  &lt;div id="error"&gt;
      &lt;%= f.error_messages %&gt;
  &lt;/div&gt;
  
    &lt;%= f.label :number, "Certificate Number" %&gt;
    &lt;%= f.text_field :number %&gt;   &lt;br/&gt;
  
      &lt;%= f.label :num_of_shares, "Number Of Shares" %&gt;
      &lt;%= f.text_field :num_of_shares %&gt; &lt;br/&gt;
  
      &lt;% f.fields_for :custodian do |custodian| -%&gt;
          &lt;%= custodian.label :name, "Custodian Name" %&gt;
          &lt;%= custodian.text_field :name %&gt;
      &lt;% end -%&gt;
  
      &lt;%= f.submit "Issue Certificate", :disable_with =&gt; 'Working....' %&gt;
  
  &lt;% end -%&gt;
  </code></pre>
  
  <p>Now, for some reason, in my controller on line 4: <code>@certificate.custodian.build
  </code></p>
  
  <p>I'm getting this error: <code>undefined method 'build' for nil:NilClass</code></p>
  
  <p>Can any one please help?</p>