Aaron Reimann
2007-Jan-04 16:48 UTC
view/_form.rhtml help, joining multiple tables, one form
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 strange. 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-pRMrFfBWTvzXLFgcqHozlA@public.gmane.org 2, julie, smith, js-mUwBmriqYc0RkyM7CKMC1Q@public.gmane.org ---------- 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---