title: Rails 4 Strong Parameters when multiple-level accepts_nested_attributes_for
body: <p>I am having an issue when I attempt to save a model that has multiple levels of accepts_nested_attribetus_for.</p>
  
  <p>My use case is that there is a user page, where the user can create multiple questions, and also multiple answers per question.</p>
  
  <p>Whats happening is that since there can be multiple questions on the submit page, the parameters hash for the user, on submit, looks like: </p>
  
  <pre><code>{"user"=&gt;{"questions_attributes"=&gt;{"0"=&gt;{"desc"=&gt;"question", "answers_attributes"=&gt;{"0"=&gt;{"ans"=&gt;""}}}}}}
  </code></pre>
  
  <p>And as such, the error I am getting is "Unpermitted parameter: 0". How would I setup the strong parameters permissions correctly, so that I can save all models correctly? I can cycle through the questions, and save each one individually, and that works, but I was hoping there would be a cleaner way of doing it.</p>
  
  <p>user.rb</p>
  
  <pre><code>has_many :questions
  accepts_nested_attributes_for :questions
  </code></pre>
  
  <p>question.rb</p>
  
  <pre><code>belongs_to :user
  has_many :answers
  accepts_nested_attributes_for :answers
  </code></pre>
  
  <p>answer.rb</p>
  
  <pre><code>belongs_to :question
  </code></pre>
  
  <p>users_controller.rb</p>
  
  <pre><code>def update
      user = User.find_by_id params[:id]
      user.questions.create question_params(params[:user])
  end
  
  def question_params(params)
      params.require(:question_attributes).permit(:desc, {:answers_attributes =&gt; [:ans]}
  end
  </code></pre>