Forum: Ruby on Rails view/_form.rhtml help, joining multiple tables, one form

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.
D35227e67a52a5acda55dec8b3353684?d=identicon&s=25 Aaron Reimann (Guest)
on 2007-01-06 19:31
(Received via mailing list)
I am not sure how to build a view/people/_form.rhtml that needs to pull
data from multiple tables.  The "magic" for Rails makes it a little

I am new at this, and any examples you can through my way, or actual
code, would be greatly appreciated.

Here are some simplified tables that I am using:

Table 1:
table name: people
columns: id, fname, lname, email

example data:
1, bob, smith, bobs@bobiscool.doh
2, julie, smith, js@wowsers.doh

Table 2:
table name: interests
columns: id, name

example data:
1, Soccer
2, Tennis
3, Football

Table 3:
table name: people_interests
columns: id_person, id_interest

example data:
1, 1
1, 3
2, 1

that would tell you that:
Bob is interested in Soccer and Football
Julie is interested in only Soccer

So I want to create a form that will have these fields:
First Name: __________
Last Name: __________
Email: __________

What are your interests?

Checkbox - Soccer
Checkbox - Tennis
Checkbox - Football


I am assuming that my view/_form.rhtml would look something like this:

<p><label for="person_fname">First Name</label><br/>
<%= text_field 'person', 'fname'  %></p>
<p><label for="person_lname">Last Name</label><br/>
<%= text_field 'person', 'lname'  %></p>
<p><label for="person_email">Email</label><br/>
<%= text_field 'person', 'email'  %></p>

<% for interest in @interests %>
  <p><%= check_box('interest', 'id') %></p>
<% end %>

But I am not sure how to "link" it all together.  In PHP I would get
$_POST['fname'], etc and put that in the table, then grab the posted
check boxes and put those id #'s in the people_interests table.
This topic is locked and can not be replied to.