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 %> <p>try to marshal the data for each "metadata_entry" has_many relationship</p> <% @metadata.metadata_entries.each_with_index do |entry, index| %> <p>this is obviously wrong, how do I index this??</p> <input type="text" name="metadata[metadata_entries][<%=index%>][label]" value="<%=entry.label%>"/> <% 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. -- Posted via http://www.ruby-forum.com/.
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 Morris <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 %> > <p>try to marshal the data for each "metadata_entry" has_many > relationship</p> > <% @metadata.metadata_entries.each_with_index do |entry, index| %> > <p>this is obviously wrong, how do I index this??</p> > <input type="text" > name="metadata[metadata_entries][<%=index%>][label]" > value="<%=entry.label%>"/> > <% 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. > -- > Posted viahttp://www.ruby-forum.com/.
Sahil Dave, Ahh perfect. That makes sense. Appreciate the help, -C Sahil Dave 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 Morris <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>-- Posted via http://www.ruby-forum.com/.