# Examples of forms using nested resources?

**URL:** <https://www.ruby-forum.com/t/examples-of-forms-using-nested-resources/152064>\
**Category:** Rails\
**Created:** [October 29, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/examples-of-forms-using-nested-resources/152064 "2008-10-29T17:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [October 29, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/examples-of-forms-using-nested-resources/152064/1 "2008-10-29T17:33:12Z")

</div>

Does anyone know of some examples of simple forms using nested  
resources?

I want to have a parent record, with many child records all on the one  
form, and have all the add, edit, delete etc methods available on the  
children.

This seems to be an obvious use for the nested routes that are generated  
by nested resources so I assume someone has this all worked out  
somewhere. Or is it so obvious that no explanation is required?

Thanks

John S.

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [October 29, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/examples-of-forms-using-nested-resources/152064/2 "2008-10-29T18:56:29Z")

</div>

I think what your looking for is the index attribute on your form  
fields:

\<% form\_for :resourece do |form| %\>  
\<% resourece.sub\_resources.each do |sr| %\>  
\<% fields\_for :sr, sr do |sr\_fields| %\>  
\<%= sr\_fields.text\_field :name, :index =\> sr.id %\>  
\<% end %\>  
\<% end %\>  
\<% end %\>

then the params will be sent to the controller like so:  
sub\_resource[i][:name]  
where “i” is the index set in the above field

something like that anyway… hope that sets you on the right track…  
you may want to search around the group a bit more I know there has  
been discussions on this.

good luck!  
Tim

On Oct 29, 9:33 am, John S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
