# Nested\_attributes and fields\_for and ajax

**URL:** <https://www.ruby-forum.com/t/nested-attributes-and-fields-for-and-ajax/178183>\
**Category:** Rails\
**Created:** [October 30, 2009, 10:22am UTC](https://www.ruby-forum.com/t/nested-attributes-and-fields-for-and-ajax/178183 "2009-10-30T10:22:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrmanishs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mrmanishs](https://www.ruby-forum.com/u/mrmanishs)\
**Post date:** [October 30, 2009, 10:22am UTC](https://www.ruby-forum.com/t/nested-attributes-and-fields-for-and-ajax/178183/1 "2009-10-30T10:22:14Z")

</div>

Hello there, I have a form\_for and a fields\_for within the form\_for. I  
want to add/delete item in the fields\_for and refresh the items in the  
fields\_for list without having to regenerate the whole form.

Now, if I set up link\_to\_remotes for adding/deleting the item in  
fields\_for, it calls the controller, with the proper item to add/  
delete, but what do I do to refresh the items in the fields\_for after  
the collection has been modified? Because the fields\_for fields are  
part of nested\_attributes, how do I tell the view what the new  
collection is to generate? Is there a way to convert a collection in a  
controller to a fields\_for collection, so the view can process it?

This has been frustrating to figure out…

---

<div class="post-metadata">

**Author:** ![mrmanishs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mrmanishs](https://www.ruby-forum.com/u/mrmanishs)\
**Post date:** [October 30, 2009, 2:53pm UTC](https://www.ruby-forum.com/t/nested-attributes-and-fields-for-and-ajax/178183/2 "2009-10-30T14:53:18Z")

</div>

Hi… you might want to take a look at:

> **[GitHub - alloy/complex-form-examples: Simple Rails application which shows...](https://github.com/alloy/complex-form-examples)**
>
> Simple Rails application which shows the use of NestedAttributes and AutosaveAssociation. - GitHub - alloy/complex-form-examples: Simple Rails application which shows the use of NestedAttributes an...

And: [GitHub - ryanb/complex-form-examples: Various ways to handle multi-model forms in Rails.](http://github.com/ryanb/complex-form-examples)

Both of these are interesting sample apps loaded with good coding  
ideas. I don’t believe either of them uses AJAX or link\_to\_remote  
exactly the way you intended, but at least they might give you some  
new ideas and/or lead you in the right direction.

- pat  
[http://patshaughnessy.net](http://patshaughnessy.net)

---

<div class="post-metadata">

**Author:** ![mrmanishs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@mrmanishs](https://www.ruby-forum.com/u/mrmanishs)\
**Post date:** [October 30, 2009, 3:12pm UTC](https://www.ruby-forum.com/t/nested-attributes-and-fields-for-and-ajax/178183/3 "2009-10-30T15:12:02Z")

</div>

These are good examples of using form\_for/fields\_for nested  
attributes, which I have no problems with. It’s integrating Ajax with  
fields\_for which is causing pain.
