title: Some records are not being saved in nested forms
body: <p>So im doing this quiz app.
  This is my quizzes controller:</p>
  
  <pre><code># encoding: utf-8
  class QuizzesController &lt; ApplicationController
    before_action :set_quiz, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!
    # GET /quizzes
    # GET /quizzes.json
    def index
      @quizzes = Quiz.all
    end
  
    # GET /quizzes/1
    # GET /quizzes/1.json
    def show
    end
  
    # GET /quizzes/new
    def new
      @quiz = Quiz.new
      10.times do
        question = @quiz.questions.build
        4.times { question.answers.build }
      end
      5.times do 
          @quiz.links.build 
      end
    end
  
    # GET /quizzes/1/edit
    def edit
    end
  
    # POST /quizzes
    # POST /quizzes.json
    def create
      @quiz = Quiz.new(quiz_params)
  
      respond_to do |format|
        if @quiz.save
          format.html { redirect_to @quiz, notice: 'Quiz was successfully created.' }
          format.json { render action: 'show', status: :created, location: @quiz }
        else
          format.html { render action: 'new' }
          format.json { render json: @quiz.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /quizzes/1
    # PATCH/PUT /quizzes/1.json
    def update
      respond_to do |format|
        if @quiz.update(quiz_params)
          format.html { redirect_to @quiz, notice: 'Quiz was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @quiz.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /quizzes/1
    # DELETE /quizzes/1.json
    def destroy
      @quiz.destroy
      respond_to do |format|
        format.html { redirect_to quizzes_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_quiz
        @quiz = Quiz.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def quiz_params
        params.require(:quiz)
        .permit(:content,
        links_attributes: [:id, :name, :www],
        question_attributes: [:id, :content,
        answer_attributes: [:id, :content, :correct]])
      end
  end
  </code></pre>
  
  <p>Question controller:</p>
  
  <pre><code># encoding: utf-8
  class QuestionsController &lt; ApplicationController
    before_action :set_question, only: [:show, :edit, :update, :destroy]
    before_action :set_quizzes, only: [:new, :show, :edit, :update, :destroy]
  
    # GET /questions
    # GET /questions.json
    def index
      @questions = Question.all
    end
  
    # GET /questions/1
    # GET /questions/1.json
    def show
    end
  
    # GET /questions/new
    def new
      @question = Question.new
    end
  
    # GET /questions/1/edit
    def edit
    end
  
    # POST /questions
    # POST /questions.json
    def create
      @question = Question.new(question_params)
  
      respond_to do |format|
        if @question.save
          format.html { redirect_to @question, notice: 'Question was successfully created.' }
          format.json { render action: 'show', status: :created, location: @question }
        else
          format.html { render action: 'new' }
          format.json { render json: @question.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /questions/1
    # PATCH/PUT /questions/1.json
    def update
      respond_to do |format|
        if @question.update(question_params)
          format.html { redirect_to @question, notice: 'Question was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @question.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /questions/1
    # DELETE /questions/1.json
    def destroy
      @question.destroy
      respond_to do |format|
        format.html { redirect_to questions_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_question
        @question = Question.find(params[:id])
      end
      def set_quizzes
      @quizzes = Quiz.find(:all).map do |quiz|
        [quiz.content, quiz.id]
      end
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def question_params
        params.require(:question)
        .permit(:content, :quiz_id,
        answer_attributes: [:id, :content, :correct])
      end
  end
  </code></pre>
  
  <p>And answer:</p>
  
  <pre><code>    # encoding: utf-8
      class AnswersController &lt; ApplicationController
        before_action :set_answer, only: [:show, :edit, :update, :destroy]
        before_action :set_questions, only: [:new, :show, :edit, :update, :destroy]
        # GET /answers
        # GET /answers.json
        def index
          @answers = Answer.all
        end
  
        # GET /answers/1
        # GET /answers/1.json
        def show
        end
  
        # GET /answers/new
        def new
          @answer = Answer.new
        end
  
        # GET /answers/1/edit
        def edit
        end
  
        # POST /answers
        # POST /answers.json
        def create
          @answer = Answer.new(answer_params)
  
          respond_to do |format|
            if @answer.save
              format.html { redirect_to @answer, notice: 'Answer was successfully created.' }
              format.json { render action: 'show', status: :created, location: @answer }
            else
              format.html { render action: 'new' }
              format.json { render json: @answer.errors, status: :unprocessable_entity }
            end
          end
        end
  
        # PATCH/PUT /answers/1
        # PATCH/PUT /answers/1.json
        def update
          respond_to do |format|
            if @answer.update(answer_params)
              format.html { redirect_to @answer, notice: 'Answer was successfully updated.' }
              format.json { head :no_content }
            else
              format.html { render action: 'edit' }
              format.json { render json: @answer.errors, status: :unprocessable_entity }
            end
          end
        end
  
        # DELETE /answers/1
        # DELETE /answers/1.json
        def destroy
          @answer.destroy
          respond_to do |format|
            format.html { redirect_to answers_url }
            format.json { head :no_content }
          end
        end
  
        private
          # Use callbacks to share common setup or constraints between actions.
          def set_answer
            @answer = Answer.find(params[:id])
          end
          def set_questions
            @questions = Question.find(:all).map do |question|
            [question.content, question.id]
          e
  
  nd
      end
      # Never trust parameters from the scary internet, only allow the white list through.
      def answer_params
        params.require(:answer).permit(:content, :correct, :question_id)
      end
  end
  
  Model:
  
      class Quiz &lt; ActiveRecord::Base
        has_and_belongs_to_many :users
        has_many :questions
        has_many :links
        accepts_nested_attributes_for :links
        accepts_nested_attributes_for :questions, :reject_if =&gt; lambda { |a| a[:content].blank? }, :allow_destroy =&gt; true
      end
  
      class Question &lt; ActiveRecord::Base
        belongs_to :quiz
        has_many :answers
        accepts_nested_attributes_for :answers, :reject_if =&gt; lambda { |a| a[:content].blank? }, :allow_destroy =&gt; true
      end
  </code></pre>
  
  <p>And form:</p>
  
  <pre><code>&lt;%= form_for(@quiz) do |f| %&gt;
      &lt;% if @quiz.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@quiz.errors.count, "error") %&gt; prohibited this quiz from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @quiz.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
    &lt;p&gt;
      &lt;%= f.label :content, "Nazwa quizu" %&gt;
      &lt;%= f.text_field :content %&gt;
    &lt;/p&gt;
      &lt;ol&gt; &lt;%= f.fields_for :links do |builder| %&gt;
      &lt;li&gt;&lt;%= render "link_fields", :f =&gt; builder %&gt;&lt;/li&gt;
    &lt;% end %&gt;
    &lt;/ol&gt;
    &lt;ol&gt;&lt;%= f.fields_for :questions do |builder| %&gt;
      &lt;li&gt;&lt;%= render "question_fields", :f =&gt; builder %&gt;&lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ol&gt;
    &lt;p&gt;&lt;%= f.submit "Submit" %&gt;&lt;/p&gt;
  </code></pre>
  
  <p>The form works for links, but when it comes to saving questions and answers it does nothing (when i listed all records from database, there where only questions i saved using another form and method). The code below was created to display questions made with this other form and it worked, but since I changed the method a bit, do I have to change the code in view? Or maybe it's controllers fault?</p>
  
  <p>This is my code for displaying:</p>
  
  <pre><code>&lt;div class="row"&gt;               
        &lt;div  id="prezentacja" class="col-md-7 col-lg-7 col-sm-12 prezentacja3 center-block3"&gt;                
            &lt;p class="header2 roboto"&gt;  
              &lt;%= @quiz.content %&gt;
            &lt;/p&gt;      
            &lt;%= notice %&gt;         
            &lt;div class="col-md-12 col-lg-12" &gt;
                &lt;% @quiz.questions.each do |question| %&gt;
                &lt;div id="answer-&lt;%= question.id %&gt;" class="question col-md-12 col-lg-12"&gt;
                    &lt;h4&gt;&lt;%= question.content %&gt;&lt;/h4&gt;
                    &lt;% question.answers.each do |answer| %&gt; 
                    &lt;div class="col-lg-4 answer"&gt;
                      &lt;p&gt;&lt;%= answer.content %&gt;&lt;/p&gt;
                    &lt;/div&gt;
                    &lt;% end %&gt;
                &lt;/div&gt;
                &lt;% end %&gt;
            &lt;/div&gt;
        &lt;%= Answer.all.to_a %&gt;
        &lt;/div&gt;                
        &lt;div  id="prezentacja" class=" col-md-3 col-lg-3 col-sm-12 prezentacja3 center-block3"&gt;                           
        &lt;div class="row"&gt; 
            &lt;div class="col-md-12 col-lg-12 col-sm-12"&gt; 
                &lt;% @quiz.links.each do |link| %&gt;        
                  &lt;%= link_to link.name, "http://#{link.www}" %&gt; 
                &lt;% end %&gt;
            &lt;/div&gt;                    
        &lt;/div&gt;                                    
        &lt;div class="row"&gt;                     
        &lt;div class="col-md-12 col-lg-12 col-sm-12"&gt;                       
        &lt;p&gt;Dupa dupa dupa&lt;/p&gt;
        &lt;/div&gt;                
        &lt;/div&gt;                
        &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>