title: Nested models form Rails 3
body: <p>I'm following along with Railscast 196 in which R Bates makes nested forms. He has a Survey Model with a has_many association with a Questions model. Survey also accepts_nested_attributes_for :questions. In the new action of the surveys_controller, he does the following to create three question fields in the survey form</p>
  
  <pre><code>  def new
      @survey = Survey.new
      3.times { @survey.questions.build }
    end
  </code></pre>
  
  <p>and inside form_for @survey he has the following to create question fields in the form</p>
  
  <pre><code>&lt;% f.fields_for :questions do |builder| %&gt;
  
    &lt;p&gt;
      &lt;%= builder.label :content, "Question" %&gt;&lt;br /&gt;
      &lt;%= builder.text_area :content, :rows =&gt;  3 %&gt;
  
    &lt;/p&gt;
  </code></pre>
  
  <p>In the video, once he clicks on new survey, it shows the three question fields (along with other elements of the form). The question related elements of the form are not appearing for me.  I think he made this episode before Rails 3 was released, so something might have changed, however, I can't figure out what except that it's I'm not seeing the results of  doing 3.times (@survey.questions.build)</p>
  
  <p>Model</p>
  
  <pre><code>class Survey &lt; ActiveRecord::Base
    attr_accessible :name
  
    has_many :questions, :dependent =&gt; :destroy
    accepts_nested_attributes_for :questions
  end
  </code></pre>
  
  <p>Form</p>
  
  <pre><code>&lt;%= form_for @survey do |f| %&gt;
    &lt;%= f.error_messages %&gt;
    &lt;p&gt;
      &lt;%= f.label :name %&gt;&lt;br /&gt;
      &lt;%= f.text_field :name %&gt;
    &lt;/p&gt;
  
    &lt;% f.fields_for :questions do |builder| %&gt;
  
    &lt;p&gt;
      &lt;%= builder.label :content, "Question" %&gt;&lt;br /&gt;
      &lt;%= builder.text_area :content, :rows =&gt;  3 %&gt;
  
    &lt;/p&gt;
    &lt;% end %&gt;
    &lt;p&gt;&lt;%= f.submit %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>html form</p>
  
  <pre><code>&lt;form accept-charset="UTF-8" action="/surveys" class="new_survey" id="new_survey" method="post"&gt;&lt;div style="margin:0;padding:0;display:inline"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;"&gt;&lt;input name="authenticity_token" type="hidden" value="AWvA3/JpixF0C3sO8OzA5mMGsJzknvu99eovYv7M78E="&gt;&lt;/div&gt;
  
    &lt;p&gt;
      &lt;label for="survey_name"&gt;Name&lt;/label&gt;&lt;br /&gt;
      &lt;input id="survey_name" name="survey[name]" size="30" type="text"&gt;
    &lt;/p&gt;
  
    &lt;p&gt;&lt;input name="commit" type="submit" value="Create Survey"&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Update</p>
  
  <p>inside the form, I added this</p>
  
  <pre><code> &lt;%= @survey.questions %&gt;
  </code></pre>
  
  <p>and it's showing this</p>
  
  <pre><code>[#&lt;Question id: nil, survey_id: nil, content: nil, created_at: nil, updated_at: nil&gt;, #&lt;Question id: nil, survey_id: nil, content: nil, created_at: nil, updated_at: nil&gt;, #&lt;Question id: nil, survey_id: nil, content: nil, created_at: nil, updated_at: nil&gt;]
  </code></pre>
  
  <p>so the 3.times in the new action of the Survey controller is obviously working, but for some reason the fields aren't displaying when I do</p>
  
  <pre><code>&lt;% f.fields_for :questions do |builder| %&gt;
  
        &lt;p&gt;
          &lt;%= builder.label :content, "Question" %&gt;&lt;br /&gt;
          &lt;%= builder.text_area :content, :rows =&gt;  3 %&gt;
  
        &lt;/p&gt;
  </code></pre>