I’m working on an issue described in this ticket:
I’ve a nested form, in which the user can either create a new entry or
choose an existing one. Choosing an existing entry in a nested form is a
problem, because the association in the join table won’t be created (in
Rails 2.3.6 the ActiveRecord::RecordNotFound exception will be raised as
described in the ticket).
I had a look at the patch in the ticket and amended it, so when the id
in nested attributes is set, I read the record from the db and create
the association in the join table. Unfortunately, creating the
association is not working properly.
here’s my code:
# fetch the record
# create the association association.send(:add_record_to_target_with_callbacks, record)
The last two lines doesn’t create the association. I looked at the
active record code but haven’t found a way to create the association
only. All the build/create/update methods will create a new record.
Would be nice if someone who’s familiar with the active record code
could help me out! Let me know if you need more information on this.