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

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.
97e3d8ba68b082414cc3438d15c9d6e2?d=identicon&s=25 Robert Evans (Guest)
on 2006-02-20 05:27
(Received via mailing list)
Hi,

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
end

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

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.

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