# Accepts\_nested\_attributes\_for and add/remove nested model forms with JS

**URL:** <https://www.ruby-forum.com/t/accepts-nested-attributes-for-and-add-remove-nested-model-forms-with-js/168454>\
**Category:** Rails\
**Created:** [May 20, 2009, 11:45pm UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-and-add-remove-nested-model-forms-with-js/168454 "2009-05-20T23:45:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Branko\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/779978/32.png) [@Branko\_V](https://www.ruby-forum.com/u/Branko_V)\
**Post date:** [May 20, 2009, 11:45pm UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-and-add-remove-nested-model-forms-with-js/168454/1 "2009-05-20T23:45:56Z")

</div>

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: [GitHub - alloy/complex-form-examples: Simple Rails application which shows the use of NestedAttributes and AutosaveAssociation.](http://github.com/alloy/complex-form-examples/tree/master)

–  
Branko
