Edit a model and its has_many children at once?

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.

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

On Oct 14, 8:14 pm, Chris M. [email protected]

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

On Oct 14, 8:14�pm, Chris M. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs