title: Has_many through association form creation
body: <p>I have a has_many through association and I need to create a new record for <code>UserGroup</code> where the UserGroup is created within the Group controller. </p>
  
  <p>In my <code>groups</code> controller I have this method</p>
  
  <pre><code>def add
    @usergroup = UserGroup.new
  end
  </code></pre>
  
  <p>Here is my <code>UserGroup.rb</code> model</p>
  
  <pre><code>class UserGroup &lt; ApplicationRecord
    belongs_to :user
    belongs_to :group
  end
  </code></pre>
  
  <p>In the <code>add.html.erb</code> view I have it render the form whos code is listed below.</p>
  
  <pre><code>&lt;%= form_for(@usergroup) do |form| %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :user_id %&gt;
      &lt;%= form.text_field :user_id %&gt;
    &lt;/div&gt;
  
    &lt;% form.text_field :group_id, value: @usergroup.id %&gt;
  
  
    &lt;div class="actions"&gt;
      &lt;%= form.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>However I am getting this error. </p>
  
  <p><code>undefined method</code>user_groups_path' for #&lt;#:0x007fba7c11aab0>`</p>
  
  <p>Can you not create a record this way? I want to have the url presented like this <code>http://localhost:3000/groups/4/add</code>.</p>
  
  <p>Im somewhat new to Rails and forms for different models is where I get confused. Can anybody help me out with this? </p>
  
  <h3>Routes</h3>
  
  <pre><code>Rails.application.routes.draw do
    resources :maps
    devise_for :users
    resources :groups do
      get 'add', on: :member
    end
    resources :rows
  
    root to: 'maps#index'
  end
  </code></pre>