I'm terribly new to Rails, so bear with me. I have an application I am working on which deals with projects and subcontractors. There can be several subs on each project and each sub can work on several projects. I have my join table set up and has_and_belongs_to_many in both models. If I manually put data in the join table, this works in my show view: <% for subcontractor in @project.subcontractors %> <%= subcontractor.name %><br /> <% end %> I get the correct list of subcontractors belonging to this project. My question is this: How do I get data into the join table? If I were doing this in PHP, I would have a button that said "Add a Subcontractor" that would pop up a window with a dropdown where the user would select a sub. I would then refresh the page and then refresh the page and the new sub would appear in the list. What is the "Rails Way" to do the same thing? I want the user to select a sub from a dropdown, but I have no idea how to implement this. Let me phrase that better, I know how to use collection_select for a "normal" lookup table situation where I have has_many and belongs_to. It's this habtm situation that has me stymied. What needs to go in the controller and what needs to go in the view for this to work? Any help is sincerely appreciated.
on 2006-03-22 01:20
on 2006-03-22 06:44