Forum: Ruby on Rails how to represent join tables with Rails 2.3 nested attributes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C07bd8cb005f295460456e0c0f23a12d?d=identicon&s=25 Liam Morley (carpeliam)
on 2009-03-19 13:20
(Received via mailing list)
I have a model Store with a relationship Address. Because multiple
models have relationships to Address, I have a addresses_stores join
table with a corresponding StoreAddress class that contains
information specific to that store/address (store hours, phone #,
etc).

This seemed like the way to go when I was designing the DB, but now
that I'm dealing with Rails' nested_attributes, it doesn't look like
it's going to work. I'm trying to link each StoreAddress to its
corresponding Address like so:

http://pastie.org/420843

You can see that on line 19, I'm calling fields_for(:store_addresses)
and passing a StoreAddress that should be linked to a corresponding
Address. The problem is, I don't know how to link the StoreAddress to
the Address if the Address itself is a new record. Even if this were
to work, I'm not sure exactly what params would have to look like so
that StoreAddress objects were linked with corresponding Address
objects, considering the fact that multiple addresses can be submitted
in the form.

So, first question is, what does params have to look like so that I
can submit StoreAddress objects right alongside Address objects in a
Store form. Second question is, how do I get my form to submit those
params.

Any suggestions would be great. :)
This topic is locked and can not be replied to.