Forum: Ruby on Rails Instantiating multiple child objects

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.
Woei S. (Guest)
on 2006-02-04 01:22
(Received via mailing list)
Hi,

I've been tinkering a bit with Ruby lately, and is truly amazed by its
automation, however some of it is a bit arcane for a newbie to
understand :|

Let's say for instance I have a object Person which has_many
VehicleRegistrations, and I want to have a form that would enable me to
instantiate many VehicleRegistrations at once.

So supposing my form enables 2 vehicleregistrations to be entered
alongside with the fields for Person, do I use something like

<%= text_field 'Person.VehicleRegistrations[]', 'licenseNumber' %>
<%= text_field 'Person.VehicleRegistrations[]', 'vehicleManufacturer' %>
<%= text_field 'Person.VehicleRegistrations[]', 'vehicleMake' %>

<%= text_field 'Person.VehicleRegistrations[]', 'licenseNumber' %>
<%= text_field 'Person.VehicleRegistrations[]', 'vehicleManufacturer' %>
<%= text_field 'Person.VehicleRegistrations[]', 'vehicleMake' %>

And hope that formTagHelper will be smart to realise that Person has a
has_many relationship with VehicleRegistrations and munge in the field
values for the array of VehicleRegistration?

Thanks
This topic is locked and can not be replied to.