Hi all, A bit stuck with a complex form.
I've 2 models, events and bands. bands have many events, and events have many bands, so... they're related with a has_and_belongs_to_many, with the appropriate joining table. In my new events form I've got some jquery to add new bands dynamically. in the _band form that's generated, I have a collection_select drop down menu that has a list of all the bands //controller @bands = Band.order('"band_name" ASC ') // form ff.collection_select :band_name, @bands, :band_name, :band_name When I select a band from the list the event saves fine, has the correct band or bands associated, but for each band it makes a new band instance as well. I want it to just associate the band with the event. currently: If I have 3 bands saved, beatles, stones and eagles I make a new event and select 'beatles', from the drop down then save, a new event is saved, and associated with a band called beatles BUT, there are now 2 bands called beatles in the database. I want it to be associated with the original beatles I've tried using ff.collection_select :id, @bands, :id, :band_name passing in the id instead as indicated in the nested_attributes docs (http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html) but this returns a 404 error I'm getting this in the logs: Band Load (0.3ms) SELECT "bands".* FROM "bands" INNER JOIN "bands_events" ON "bands".id = "bands_events".band_id WHERE ("bands_events".event_id = NULL ) AND ("bands"."id" IN (1)) Completed in 63ms Rendered layouts/_header.html.haml (13.3ms) Rendered site/404.html.haml within layouts/error (169.8ms) it looks like it's getting an id for bands, but the id for the event is NULL, any ideas how to get this going??? any help appreciated :) if you wanna see other bits of code also let me know, I didn't want the post getting too long Mike -- Posted via http://www.ruby-forum.com/. -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.