title: Rails 6 & route for custom post- action for nested resource & form
body: <p>I need to make a separate create action for the nested Answer resource, such as <em>create_xhr</em>, which will be called in the form on the parent resource.<br />
  This is what the route for the Answer resource looks like:</p>
  <pre class="lang-rb prettyprint-override"><code>  namespace :admin do
      resources :tests do
        resources :questions, shallow: true, except: %i[index] do
          resources :answers, shallow: true, except: %i[index]
        end
      end
    end
  </code></pre>
  <p>The path should look something like this:</p>
  <pre><code>post '/questions/:question_id/answers/create_xhr
  </code></pre>
  <p>So that in the Answers controller, the new object is associated with the current Question.<br />
  Now I've come to an option:</p>
  <pre class="lang-rb prettyprint-override"><code>  namespace :admin do
      resources :tests do
        resources :questions, shallow: true, except: %i[index] do
          resources :answers, shallow: true, except: %i[index] do
            post :create_xhr, on: :new
          end
        end
      end
    end
  </code></pre>
  <p>I get the route:</p>
  <pre><code>create_xhr_new_admin_question_answer POST   /admin/questions/:question_id/answers/new/create_xhr(.:format)  admin/answers#create_xhr
  </code></pre>
  <p>And then I create a form on the show page for Question:</p>
  <pre class="lang-rb prettyprint-override"><code>&lt;%= form_with url: create_xhr_new_admin_question_answer_path(@question), local: false do |form| %&gt;
  </code></pre>
  <p>But the parameters of the new Answer do not come inside the <strong>&quot;answer&quot;</strong> key:</p>
  <pre><code>Parameters: {&quot;authenticity_token&quot;=&gt;&quot;[FILTERED]&quot;, &quot;body&quot;=&gt;&quot;text&quot;, &quot;correct&quot;=&gt;&quot;false&quot;, &quot;commit&quot;=&gt;&quot;Add answer&quot;, &quot;lang&quot;=&gt;&quot;en&quot;, &quot;question_id&quot;=&gt;&quot;7&quot;}
  </code></pre>
  <p>It must be:</p>
  <pre><code>Parameters: {&quot;authenticity_token&quot;=&gt;&quot;[FILTERED]&quot;, &quot;answer&quot;=&gt;{&quot;body&quot;=&gt;&quot;text&quot;, &quot;correct&quot;=&gt;&quot;false&quot;}, &quot;commit&quot;=&gt;&quot;Add answer&quot;, &quot;lang&quot;=&gt;&quot;en&quot;, &quot;question_id&quot;=&gt;&quot;7&quot;}
  </code></pre>
  <p>If I specify a model in the form instead of a URL, then rails selects the default action <strong>create</strong>.</p>
  <p>I also tried writing the route directly in the Admin namespace block:</p>
  <pre><code>post '/questions/:question_id/answers/create_xhr', to: 'answers#create_xhr', as: :create_answer_on_question
  </code></pre>
  <p>and get a route:</p>
  <pre><code>admin_create_answer_on_question POST   /admin/questions/:question_id/answers/create_xhr(.:format)   admin/answers#create_xhr
  </code></pre>
  <p>However, the problem with the parameters coming to the controller is the same.</p>
  <p>Where am I wrong?<br />
  Should I write the router or the form differently?</p>