Julian ''Julik'' Tarkhanov
2005-May-08 23:42 UTC
Form select helpers for m-to-n and m-to-m
I think this already has been asked about, but still. How do I easily generate a select-multiple and select form element (or a checkbox array) for an ActiveRecord that has a m-t-m or m-to-n relationship? Of course I would love to have the existing relations already selected etc. In my current app I have a Work, which has 1 client and many Activities. I use this for the select of the client: <%= collection_select ''work'', ''client'', Client.find_all, :id, :name, @work.client.id %> This gives me an empty option tag in the beginning of the form when editing. How can I pump the client ID which already is set for the record for an edit action and an empty option for create action? I am sure this is covered in one fo the tutorials but was changed in one of the recent verisons. The Rdocs are also not so clear on that one. -- Julian "Julik" Tarkhanov