title: Rails associations and MVC
body: <p>in my Rails app I have a User model and a Team model, linked through a User_Team model.</p>
  
  <p>What I'm trying to do is to ask Rails to validate and create a new user only if the params used to create it come with a valid team_code param.</p>
  
  <p>Basically I need to:</p>
  
  <ol>
  <li>check the Team table</li>
  <li>look if a team with the provided team_code exists</li>
  <li>only in this case allow the creation of the user</li>
  <li>link the user to the team</li>
  </ol>
  
  <p>Which is the best way to do this?  Where should I put the logic?  In the controller? In the user validation model?</p>
  
  <p>Even just a few hints would be helpful!</p>
  
  <p><strong>UPDATE #1</strong>
  The team_code is an attribute of the Team model.  Teams are created previously (not during user creation).  I need that each user - in order to be created - has an existing team to enter at user creation time.</p>
  
  <p>Thanks,
  Augusto</p>