Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All,</p> <p><a href="https://stackoverflow.com/users/155351/hakunin">Hakunin</a> was on the money. I was calling the partial in more than one spot. The second spot was in my helper method "link_to_add_fields." I use this to add fields using javascript.</p> <p>The method looked like this:</p> <pre><code># generates add fields on a dynamic form def link_to_add_fields(name, f, association, locals={}) 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(name, "#", :class =&gt; "dynamic_add", 'data-association' =&gt; "#{association}", 'data-content' =&gt; "#{fields}") end </code></pre> <p>Notice that this does not allow any locals to be passed to the render method. I changed it like so:</p> <pre><code># generates add fields on a dynamic form def link_to_add_fields(name, f, association, locals={}) 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", locals.merge!(:f =&gt; builder)) end link_to(name, "#", :class =&gt; "dynamic_add", 'data-association' =&gt; "#{association}", 'data-content' =&gt; "#{fields}") end </code></pre> <p>Now my link_to_add_fields call in my _form partial looks like this:</p> <pre><code>&lt;%= link_to_add_fields "Add a comment", f, :comments, :tester =&gt; true %&gt; </code></pre> <p>...and I can dynamically add fields to my form AND pass additional locals. Hopefully, this will help someone else out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload