I am trying to make a simple application which consists of contacts and
class Contact < ActiveRecord::Base
class Address < ActiveRecord::Base
I would like to be able to edit/add addresses from within the edit/add
of the contact. I scaffolded the contact and address objects and
modified the contacts/_form partial as follows:
<%= error_messages_for ‘contact’ %>
<%= text_field 'contact', 'name' %>
The addresses/_form partial looks like this:
<%= error_messages_for 'address' %>
<%= text_field 'address', 'line_1' %>
<%= text_field 'address', 'line_2' %>
<%= text_field 'address', 'city' %>
<%= text_field 'address', 'state' %>
<%= text_field 'address', 'zip' %>
I am running into to issues with this design. 1) I’ve manually added
address objects into the table and when i go to addresses/edit/1, it
renders the two addresses but the fields are blank. Like it sees the
records, but its not getting put into the partial. 2) After I get the
addresses displayed, how would I go about saving the contact and all of
the addresses in a single post-back?
I’ve been googling for days, and it seems this should be a simple thing
that has been encountered before.
Thanks in advance for your help!