Forum: Ruby on Rails Examples of forms using nested resources?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44a43e7fef8e933e802a7802b4bd3525?d=identicon&s=25 John Small (johnsmall)
on 2008-10-29 17:33
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 Small
Ab0b702e7fcc79bb7d2c6c67f64e1b4d?d=identicon&s=25 Tim McIntyre (Guest)
on 2008-10-29 18:56
(Received via mailing list)
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 Small <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.