Instantiating multiple child objects

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 :expressionless:

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 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