title: Rails Form with belongs_to Association
body: <p>I'm very new to Rails so this may be an obvious problem, and if so I apologize.</p>
  
  <p>I am trying to create a form for creating a  <code>User</code> record, which has a <code>belongs_to</code> association with a <code>Team</code> model. What I've done so far is the following...</p>
  
  <pre><code>&lt;% form_for @user, url: {action: "create"} do |f| %&gt;
    &lt;%= f.text_field :name %&gt;
    &lt;%= f.text_field :email %&gt;
  
    &lt;% f.fields_for :team do |team| %&gt;
      &lt;%= team.collection_select(:team_id, Team.all, :id, :name) %&gt;
    &lt;% end %&gt;
    &lt;%= f.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This seems to work well enough, but when creating the User record I'm running into trouble.</p>
  
  <pre><code>def create
    @team = Team.find(params[:user][:team][:team_id])
    @team.users.create(user_params)
    # Ignoring error checking for brevity
  end
  
  def user_params
      params.require(:user).permit(:name, :email)
  end
  </code></pre>
  
  <p>The params now contains a field for <code>team_id</code> which is not an attribute of the <code>User</code> model, and thus the creation fails. I'm not sure how to go about addressing that, let alone whether or not this is the appropriate way to approach this. Any advice would be greatly appreciated!</p>