title: Rails 3 content_for issues
body: <p>I've recently built a fairly deep nested form using     http:// github.com/timriley/complex-form-examples for guidance. The form partial uses the following in order to render new fields when a link is clicked:</p>
  
  <pre><code>&lt;%= yield :warehouses_fields_template %&gt;
  &lt;%= yield :ratgrades_fields_template %&gt;
  </code></pre>
  
  <p>The content for these is generated in the ApplicationHelper as such:</p>
  
  <pre><code>def new_child_fields_template(form_builder, association, options = {})
      content_for "#{association}_fields_template" do
        options[:object] ||= form_builder.object.class.reflect_on_association(association).klass.new
        options[:partial] ||= association.to_s.singularize
        options[:form_builder_local] ||= :f
  
        content_tag(:div, :id =&gt; "#{association}_fields_template", :style =&gt; "display: none") do
          form_builder.fields_for(association, options[:object], :child_index =&gt; "new_#{association}") do |f|
            render(:partial =&gt; options[:partial], :locals =&gt; {options[:form_builder_local] =&gt; f})
          end
        end
      end unless content_given?("#{association}_fields_template")
  end
  
  def content_given?(name)
      content = instance_variable_get("@content_for_#{name}")
      ! content.nil?
  end
  </code></pre>
  
  <p>Everything seemed to be working perfectly on rails 2.3.8, but after upgrading to Rails 3 rc today the templates are no longer loaded. Has something changed that would make the above code invalid? Anyone else noticing the same problem?</p>
  
  <p>Any help would be greatly appreciated,
  Thanks!</p>
  
  <p>For reference, this is the relevant jQuery code as well:</p>
  
  <pre><code>$(function() {
    $('form a.add_child').live('click', function() {
      // Setup
      var assoc   = $(this).attr('data-association');           // Name of child
      var content = $('#' + assoc + '_fields_template').html(); // Fields template
  
      // Make the context correct by replacing new_&lt;parents&gt; with the generated ID
      // of each of the parent objects
      var context = ($(this).parents('.fields').children('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
  
      // context will be something like this for a brand new form:
      // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
      // or for an edit form:
      // project[tasks_attributes][0][assignments_attributes][1]
      if(context) {
        var parent_names = context.match(/[a-z]+_attributes/g) || []
        var parent_ids   = context.match(/[0-9]+/g)
  
        for(i = 0; i &lt; parent_names.length; i++) {
          if(parent_ids[i]) {
            content = content.replace(
              new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
              '$1[' + parent_ids[i] + ']'
            )
          }
        }
      }
  
      // Make a unique ID for the new child 
      var regexp  = new RegExp('new_' + assoc, 'g');
      var new_id  = new Date().getTime();
      content     = content.replace(regexp, new_id)
  
      $(this).parent().before(content);
      return false;
    });
  });
  </code></pre>
  
  <p>I've included a Gist with some more of the relevant pages if it'll help:  <a href="http://gist.github.com/536704" rel="nofollow noreferrer">http://gist.github.com/536704</a></p>