title: Model Associations in Rails - many-to-many for multiple models
body: <p>I'm trying to understand and implement Active Record Associations in Rails and am having some trouble understanding how to put together the specific relationships I need.</p>
  
  <p>I have a Recipe model and an Ingredients model. Many Ingredients will belong to a single Recipe and therefore, a Recipe will have many Ingredients. I am having trouble grasping how this is handled through MySQL and how to implement these relationships in the models correctly. Here is the (relatively sparse) code I have, so far:</p>
  
  <p>models/recipe.rb</p>
  
  <pre><code>class Recipe &lt; ActiveRecord::Base
    has_many :ingredients
  end
  </code></pre>
  
  <p>models/ingredient.rb</p>
  
  <pre><code>class Ingredient &lt; ActiveRecord::Base
    has_and_belongs_to_many :recipes
  end
  </code></pre>
  
  <p>However, I'm fairly certain the association line in ingredient.rb is incorrect.</p>
  
  <p>How would I correctly implement these relationships?</p>