diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb
index f68035c..bf5e741 100644
--- a/app/controllers/people_controller.rb
+++ b/app/controllers/people_controller.rb
@@ -12,11 +12,19 @@ def show
# GET /people/new
def new
- @person = Person.new
- end
+ @person = Person.new
+ @person.build_address
+end
+
+def edit
+ @person.build_address if @person.address.nil?
+end
+
+
# GET /people/1/edit
def edit
+ @person.build_address if @person.address.nil?
end
# POST /people or /people.json
@@ -65,6 +73,9 @@ def set_person
# Only allow a list of trusted parameters through.
def person_params
- params.expect(person: [ :first_name, :last_name, :date_of_birth, :social_security_number, :email, :relationship_id ])
- end
+ params.require(:person).permit(
+ :first_name, :last_name, :date_of_birth, :email, :relationship_id,
+ address_attributes: [ :city, :street_address, :state ]
+ )
+ end
end
diff --git a/app/models/person.rb b/app/models/person.rb
index e8c2489..98c7c46 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -1,5 +1,5 @@
+# app/models/person.rb
class Person < ApplicationRecord
- belongs_to :relationship
-
has_one :address, dependent: :destroy
-end
+ accepts_nested_attributes_for :address
+end
\ No newline at end of file
diff --git a/app/views/people/_form.html.erb b/app/views/people/_form.html.erb
index 0d19245..4a6404c 100644
--- a/app/views/people/_form.html.erb
+++ b/app/views/people/_form.html.erb
@@ -2,7 +2,6 @@
<% if person.errors.any? %>
<%= pluralize(person.errors.count, "error") %> prohibited this person from being saved:
-
<% person.errors.each do |error| %>
- <%= error.full_message %>
@@ -25,7 +24,7 @@
<%= form.label :date_of_birth, style: "display: block" %>
<%= form.date_field :date_of_birth %>
-
+
<%= form.label :social_security_number, style: "display: block" %>
<%= form.text_field :social_security_number %>
@@ -41,6 +40,29 @@
<%= form.text_field :relationship_id %>
+ <%= form.fields_for :address do |address_form| %>
+
+ Address
+
+
+ <%= address_form.label :city, style: "display: block" %>
+ <%= address_form.text_field :city %>
+
+
+
+ <%= address_form.label :street_address, "Street Address", style: "display: block" %>
+ <%= address_form.text_field :street_address %>
+
+
+
+ <%= address_form.label :state, style: "display: block" %>
+ <%= address_form.text_field :state %>
+
+
+
+
+ <% end %>
+
<%= form.submit %>
diff --git a/db/migrate/20260829201158_add_street_address_to_address.rb b/db/migrate/20260829201158_add_street_address_to_address.rb
new file mode 100644
index 0000000..b932f4d
--- /dev/null
+++ b/db/migrate/20260829201158_add_street_address_to_address.rb
@@ -0,0 +1,5 @@
+class AddStreetAddressToAddress < ActiveRecord::Migration[8.1]
+ def change
+ add_column :addresses, :street_address, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 36dd645..68570a3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,12 +10,13 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.1].define(version: 2026_08_29_145325) do
+ActiveRecord::Schema[8.1].define(version: 2026_08_29_201158) do
create_table "addresses", force: :cascade do |t|
t.string "city"
t.datetime "created_at", null: false
t.integer "person_id", null: false
t.string "state"
+ t.string "street_address"
t.datetime "updated_at", null: false
t.index ["person_id"], name: "index_addresses_on_person_id"
end