Rails: Nested form_for Errors: 'ActionController::UrlGenerationError'
<p>I am having trouble using the form_for correctly for my nested resources.</p>

<p>I have the following set up in my models:</p>

<p><strong>team.rb</strong></p>

<pre><code>class Team &lt; ApplicationRecord
  has_many :superheroes
  accepts_nested_attributes_for :superheroes
end
</code></pre>

<p><strong>superhero.rb</strong></p>

<pre><code>class Superhero &lt; ApplicationRecord
  belongs_to :team
end
</code></pre>

<p>My routes: <strong>routes.rb</strong></p>

<pre><code>Rails.application.routes.draw do

  root to: 'teams#index'

  resources :teams do
    resources :superheroes
  end

  get '/teams/:team_id/superheroes/:id', to: 'superheroes#show', as: 'team_superheros'

end
</code></pre>

<p>In <strong>'/app/views/superheroes/new.html.erb'</strong></p>

<pre><code>&lt;%= form_for [@team, @superhero] do |f| %&gt;
  &lt;p&gt;Name&lt;/p&gt;
  &lt;p&gt;&lt;%= f.text_field :name %&gt;&lt;/p&gt;
  &lt;p&gt;True Identity&lt;/p&gt;
  &lt;p&gt;&lt;%= f.text_field :true_identity %&gt;&lt;/p&gt;
  &lt;p&gt;&lt;%= f.submit 'SAVE' %&gt;&lt;/p&gt;
&lt;% end %&gt;
</code></pre>

<p>Lastly, in <strong>superheroes_controller.rb</strong></p>

<pre><code>def new
  @team = Team.find_by_id(params[:team_id])
  @superhero = @team.superheroes.build
end
</code></pre>

<p>I think maybe my understanding of the nested form_for isn't correct. When I navigate to the new_superhero page I originally got the following error:</p>

<pre><code>undefined method `team_superheros_path'
</code></pre>

<p>So I added the following redirection route to <strong>routes.rb</strong>: </p>

<pre><code>get '/teams/:team_id/superheroes/:id', to: 'superheroes#show', as: 'team_superheros'
</code></pre>

<p>This leaves me with the "Errors: 'ActionController::UrlGenerationError'" message with the specific error:</p>

<pre><code>No route matches {:action=&gt;"show", :controller=&gt;"superheroes", :team_id=&gt;#&lt;Team id: 1, name: "Watchmen", publisher: "DC", created_at: "2016-10-22 04:04:46", updated_at: "2016-10-22 04:04:46"&gt;} missing required keys: [:id]
</code></pre>

<p>I must just be using the form_for incorrectly. I can create superheroes in the console via: watchmen.superheroes.create(name:"The Comedian",true_identity:"Edward Blake") and when the page is generated my @superhero is a blank instance of that class.</p>

<p>Any help?</p>