Hello, I have two models. people and organisations they have a many to many relationship between them. I want to be able to create person in an organisation form and vice versa. the forms for them are according to the railscasts episode 75 complex_forms_3. which is as follows
I have a organisation form(that is created dynamically) in the person form
class Organisation < ActiveRecord::Base has_and_belongs_to_many :people after_update :save_organisations
def save_people people.each do|p| if p.should_destroy? p.destroy else p.save(false) end end end end
class Person < ActiveRecord::Base has_and_belongs_to_many :organisations after_update :save_people
def save_organisations organisations.each do|org| if org.should_destroy? org.destroy else org.save(false) end end end end
Now when i create a person or an organisation the process never gets complete. Only when i comment any one of the after_update statements The problem goes away. But in this case I can either create/update an organisation in the person form or a person in an organisation form depending upon which after_update i have disabled.
can anyone tell mne whats going wrong and how do i correct it.
Thank you.