title: Rails 4 - Nested form with accepts_nested_attributes_for controller setup?
body: <p>I'm trying to make a nested form with <code>form_for</code> and <code>fields_for</code>. After much research and in-success, not working on my project anymore. I'm just trying to recreate a railscast to see what have I done wrong.</p>
  
  <p>I'm trying to re-create the example found at <a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow">http://railscasts.com/episodes/196-nested-model-form-part-1</a> which shouldn't be that hard since the code is there, but I can't manage to create questions from the survey. Here is my code until now:</p>
  
  <pre><code>rails new surveysays
  rails g scaffold survey name:string
  rake db:migrate
  rails g scaffold question survey_id:integer content:text
  rake db:migrate
  </code></pre>
  
  <p>I'm trying to do in the exact same sequence of the video.
  My Question model:</p>
  
  <pre><code>class Question &lt; ActiveRecord::Base
    belongs_to :survey
  end
  </code></pre>
  
  <p>My Survey model:</p>
  
  <pre><code>class Survey &lt; ActiveRecord::Base
    has_many :questions, dependent: :destroy
    accepts_nested_attributes_for :questions
  end
  </code></pre>
  
  <p>My survey form with nested questions fields:</p>
  
  <pre><code>&lt;%= form_for(@survey) do |f| %&gt;
        ...
        &lt;div class="field"&gt;
          &lt;%= f.label :name %&gt;&lt;br&gt;
          &lt;%= f.text_field :name %&gt;
        &lt;/div&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, :row =&gt; 3 %&gt;
          &lt;/p&gt;
        &lt;% end %&gt;
        &lt;div class="actions"&gt;
          &lt;%= f.submit %&gt;
        &lt;/div&gt;
     &lt;% end %&gt;
  </code></pre>
  
  <p>My survey show:</p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Name:&lt;/strong&gt;
    &lt;%= @survey.name %&gt;
  &lt;/p&gt;
  
  &lt;ol&gt;
    &lt;% for question in @survey.questions %&gt;
     &lt;li&gt;&lt;%=h question.content%&gt;&lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ol&gt;
  
  &lt;%= link_to 'Edit', edit_survey_path(@survey) %&gt; |
  &lt;%= link_to 'Back', surveys_path %&gt;
  </code></pre>
  
  <p>And my SurveysController:</p>
  
  <pre><code>class SurveysController &lt; ApplicationController
   ...
  
    # GET /surveys/new
    def new
      @survey = Survey.new
      3.times { @survey.questions.build }
    end
  
   ...
  
    # POST /surveys
    # POST /surveys.json
    def create
      @survey = Survey.new(survey_params)
  
      respond_to do |format|
        if @survey.save
          format.html { redirect_to @survey, notice: 'Survey was successfully created.' }
          format.json { render :show, status: :created, location: @survey }
        else
          format.html { render :new }
          format.json { render json: @survey.errors, status: :unprocessable_entity }
        end
      end
    end
  
    ...
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_survey
         @survey = Survey.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def survey_params
         params.require(:survey).permit(:name)
      end
  end
  </code></pre>
  
  <p>As until min 5:34 and thats when it doesn't work as shown in the video and doesn't create the questions, the form appears with the 3 questions, I fill the form, but when a press <kbd>create</kbd> it doesn't create the questions:</p>
  
  <p>Loading development environment (Rails 4.1.6)
     2.1.3 :001 > s = Survey.all
       Survey Load (3.0ms)  SELECT "surveys".* FROM "surveys"
       => #]> 
     2.1.3 :002 > q = s[0].questions
       Question Load (0.6ms)  SELECT "questions".* FROM "questions"  WHERE "questions"."survey_id" = ?      [["survey_id", 2]]
       => # </p>
  
  <p>I can't see any difference between my code and the example. I even tried to make some alterations in the <code>SurveysController</code> without any success:</p>
  
  <p>Inserting question_attributes:[:id ,:content] in permit of method survey_params
  or 
  Inserting @survey.questions.create(survey_params[:questions_attributes]) after if survey.save on create method, this creates the question but with content: nill</p>
  
  <p>At this point I am stuck. I don't know what more what to do, what am I missing int the controller?
  Can anyone give me some help, thanks. </p>