title: Nested Model Forms -- How do you create an object through an association if it doesn't already exist?
body: <p>From Ryan Bates's <a href="http://asciicasts.com/episodes/197-nested-model-form-part-2" rel="nofollow">episode about nested model forms</a>, I was able to create a project with <code>concerts</code>, <code>bands</code> and <code>performances</code> that they play. I can add performances to a new concert or when I edit a concert. That's fairly simple and straightforward when I follow his tutorial.</p>
  
  <p><code>performances</code> belongs to <code>bands</code> and <code>performances</code> belongs to <code>concerts</code>. A performance will list the band playing and the time starting/ending. Bands only have a string column for its name.</p>
  
  <p>When I create a new concert and add a whole slew of performances, I'd like to, at the same time, be able to create the <code>band</code> objects if they don't already exist. Otherwise, the user has the added step(s) of creating those objects, which would be tedious.</p>
  
  <p>How, through <code>accepts_nested_attributes_for</code> or some other useful Rails feature, can I do this? I am using Rails 2.3.8</p>
  
  <p>Here are my associations:</p>
  
  <pre><code>class Band &lt; ActiveRecord::Base
    has_many :performances
    has_many :concerts, :through =&gt; :performances
  end
  
  class Concert &lt; ActiveRecord::Base
    has_many :performances
    has_many :bands, :through =&gt; :performances
    accepts_nested_attributes_for :performances, :reject_if =&gt; lambda { |a| a[:content].blank? }, :allow_destroy =&gt; true
  end
  
  class Performance &lt; ActiveRecord::Base
    belongs_to :band
    belongs_to :concert
  end
  </code></pre>