title: How to loop through has_many collection and setup a HABTM with another model
body: <p>I have Orders which has many LineItems.  LineItems has_many Leads.  Leads aren't associated to a User until a User purchases them.  The association is setup through a HABTM relationship and a join table LeadsUsers.  </p>
  
  <p>Once a User purchases a lead I need to setup the association.  I have a LeadsUsers model with the right HABTM code setup.  In my order model I have the following:</p>
  
  <pre><code>has_many :line_items
  after_save :assign_lead_to_user
  
  def assign_lead_to_user
     self.line_items.each do 
       leads_users = LeadsUsers.create :user_id =&gt; :user_id, :lead_id =&gt; line_item.lead.id
       leads_users.save
     end   
    end 
  </code></pre>
  
  <p>This method fails: undefined local variable or method `line_item'.  I know this means that it doesn't know what line_item I am referring to... Any ideas?  Ultimately I want to be able to reference User.leads.all.  </p>