Accepts_nested_attributes_for and add/remove nested model forms with JS


#1

I’ve looked at the complex_form example app on GitHub, but I’m not
sure I understand how it works.

For now I’ve managed to display the partial using the render command,
and stopped at the “add new item” link… Here’s the current code:

<%= f.error_messages %>

<p>
  <%= f.label :name %><br />
  <%= f.text_field :name %>
</p>

<table id="recipe_ingredients">
  <tr>
    <th>ingredient</th>
    <th>in units</th>
    <th>quantity</th>
    <th>delete?</th>
  </tr>
  <% f.fields_for :recipe_ingredients do |ri_f| %>
    <%= render :partial => 'recipe_ingredient', :locals => { :f =>

ri_f } %>
<% end %>


<%# Add new item link here… %>

<p>
  <%= f.label :preparation %><br />
  <%= f.text_area :preparation %>
</p>

What I’m not clear about in the example app at GitHub[1] is where the
link for creating the new item appears in the template code.
(Unfortunately, I wasn’t able to get the project up on my box, so I
don’t even know how the templates are rendered.)

If someone could explain (even if only in short) what is going on with
the app, or maybe point me to a simpler solution/example, I’d
appreciate it.

1: http://github.com/alloy/complex-form-examples/tree/master


Branko