title: How to build a devise nested resource during registration?
body: <p>During registration of a new user with Devise, I need to create a new Family object link to this new user at the same time (the user being the head of the family).</p>
  
  <p>My family model:  </p>
  
  <pre><code>belongs_to user
  </code></pre>
  
  <p>My user model:</p>
  
  <pre><code>attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :family
  has_one :family
  accepts_nested_attributes_for :family
  </code></pre>
  
  <p>In devise/registration/new.html.erb</p>
  
  <pre><code>&lt;%= simple_form_for([resource, Family.new], :as =&gt; resource_name, :url =&gt;     registration_path(resource_name), :html =&gt; {:class =&gt; 'form-vertical' }) do |f| %&gt;
    &lt;%= f.error_notification %&gt;
    &lt;%= display_base_errors resource %&gt;
    &lt;%= f.input :name, :autofocus =&gt; true %&gt;
    &lt;%= f.input :email, :required =&gt; true %&gt;
    &lt;%= f.input :password, :required =&gt; true %&gt;
    &lt;%= f.input :password_confirmation, :required =&gt; true %&gt;
  
    &lt;% f.fields_for :family do |family_form| %&gt;
      &lt;p&gt;&lt;%= family_form.label :name %&gt;&lt;/p&gt;
      &lt;p&gt;&lt;%= family_form.text_field :name %&gt;&lt;/p&gt;
    &lt;% end %&gt;
  
    &lt;%= f.button :submit, 'OK', :class =&gt; 'btn-primary' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But this is not working, I find a couple of question like this but I did not manage to fix that.</p>
  
  <p>Any idea ?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I got the following error:  </p>
  
  <pre><code>undefined method `email' for #&lt;Family:0x007f892a12c310&gt;
  </code></pre>
  
  <p>Family is a model that do not have any email, just a name. I just need to be able to create a new Family object with a name when creating a new user (and link it to the user as well).</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I have added resource.build_family in my registrations controller. The family object is correctly created and associated to the user (I can display &lt;%= resource.family %> in new.html.erb for debugging), but still no form displayed for the family.</p>