I've got a form 'tasks' and I am dynamically adding a child 'steps' form.
The 'steps' is added through a javascript call to render('steps/form').
The form loads fine, but when submitting the tasks form, the added step is not put into the database.
I assume this is because I'm not linking the two forms together, but I'm not entirely sure.
My code is Tasks/new.html.erb
<%= form_for @task, :html=>{:multipart=>true} do |f| %> <%= f.label :task_name %> <%= f.text_field :task_name %> <%= link_to "Add Step", @step, :remote=>true, :class=>'addStep %> <%= f.submit %> <% end %> <% content_for(:js) do %> $('a.addStep').click(function(){ $('div#newStep').append("<%= escape_javascript(render('steps/form'))%>"); }); <% end %>
the steps/_form.html.erb is
<p class="fields"> <%= fields_for :steps do |builder| %> <%= builder.label :title %> <%= builder.text_field :title %> <% end %>
I believe the problem is that i'm not passing 'f' or 'task' into the 'step' form, but I couldn't figure out how to do that.