Forum: Ruby on Rails How to reference a field of an associated object in a text_f

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Robert E. (Guest)
on 2006-02-20 06:27
(Received via mailing list)

I hope someone can help, I am stumped.

I have a Registration ActiveRecord object. It records registrations
for people for classes.

class Registration
   has_and_belongs_to_many :people
   has_and_belongs_to_many :scheduled_courses

I have a form that allows someone to register. A registration form
will register two people. They fill in their names, addresses, and
the classes they want to register.

I am trying to uniquely identify the first and last names of the two
registrants in my form so that the rails magic will work for filling
in the relationships. I saw that for checkboxes, you can do <%=
check_box("registration[people_ids][]", "last_name", .....
and that will make rails do the magic to populate the people_ids for
each instance of the person and last_name field.
It doesn't seem to work for text fields, e.g. <%= text_field
("registration[people_ids][]", "last_name") %>
I have tried every variant of the incantation I could, and nothing

Is my only hope to do
<%= text_field("registration", "person1_last_name") %>
<%= text_field("registration", "person2_last_name") %>


Any help on how to get a form to handle fields on related objects is
greatly appreciated.

Bob E.
This topic is locked and can not be replied to.