title: ruby, rails, railscasts example I messed up
body: <p>If you saw the <a href="http://railscasts.com/episodes/197-nested-model-form-part-2" rel="nofollow noreferrer">railscasts</a> on nested forms this is the helper method to create links dynamically. However, after I upgraded to ruby 1.9.2 and rails 3 this doesn't work and I have now idea why. </p>
  
  <pre><code>    def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index =&gt; "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f =&gt; builder)
    end
    link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
  end
  </code></pre>
  
  <p>here is the javascript</p>
  
  <pre><code> function add_fields(link, association, content) {
   var new_id = new Date().getTime();
   var regexp = new RegExp("new_" + association, "g")
   $(link).up().insert({
    before: content.replace(regexp, new_id)
   });
  </code></pre>
  
  <p>}</p>
  
  <p>When I view source this is how the link is getting rendered:</p>
  
  <pre><code>&lt;p&gt;&lt;a href="#" onclick="add_fields(this, &amp;quot;dimensions&amp;quot;, &amp;quot;&amp;quot;); return false;"&gt;Add Dimension&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p>so <code>&amp;quot;&amp;quot;</code> is not the correct information to build a new template and something is going on with how the string for fields is getting set. such as <code>fields= f.fields_for</code></p>