# Edit a model and its has\_many children at once?

**URL:** <https://www.ruby-forum.com/t/edit-a-model-and-its-has-many-children-at-once/177303>\
**Category:** Rails\
**Created:** [October 14, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/edit-a-model-and-its-has-many-children-at-once/177303 "2009-10-14T17:14:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [October 14, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/edit-a-model-and-its-has-many-children-at-once/177303/1 "2009-10-14T17:14:10Z")

</div>

I know there has to be a way to do this. Is there any way to edit a  
model, and its has\_many children in a single view?

Example:

class Metadata  
has\_many :metadata\_entries  
end

If both Metadata and MetadataEntries have a ‘label’ attribute, what  
would the view look like?

Here is my best guess, but this doesn’t work:  
------edit.html.erb----

\<% form\_for(@metadata) do |f| %\>  
\<%= f.text\_field :label %\>

try to marshal the data for each "metadata\_entry" has\_many relationship

 \<% @metadata.metadata\_entries.each\_with\_index do |entry, index| %\> 

this is obviously wrong, how do I index this??

 \<% end %\> \<%= f.submit 'Update' %\> \<% end %\>

------end edit.html.erb----

I’m running ruby 1.8.6/Rails 2.3.2.

Thanks in advance for any and all pointers.

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [October 15, 2009, 8:51am UTC](https://www.ruby-forum.com/t/edit-a-model-and-its-has-many-children-at-once/177303/2 "2009-10-15T08:51:39Z")

</div>

Try the new “accepts\_nested\_attributes\_for” feature in rails 2.3  
[http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes](http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes)

On Oct 14, 8:14 pm, Chris M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chrismalek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@chrismalek](https://www.ruby-forum.com/u/chrismalek)\
**Post date:** [October 15, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/edit-a-model-and-its-has-many-children-at-once/177303/3 "2009-10-15T15:43:46Z")

</div>

Sahil D.,

Ahh perfect. That makes sense.

Appreciate the help,  
-C

Sahil D. wrote:

> Try the new “accepts\_nested\_attributes\_for” feature in rails 2.3  
> [http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes](http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes)
> 
> On Oct 14, 8:14ï¿½pm, Chris M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
