Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3244148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:30:59+00:00 2026-05-17T18:30:59+00:00

I have some nested attributes in some models as such: class Employee < ActiveRecord::Base

  • 0

I have some nested attributes in some models as such:

class Employee < ActiveRecord::Base
  has_one :user, :as => :user_role, :dependent => :destroy
  accepts_nested_attributes_for :user, :allow_destroy => true
end

class User < ActiveRecord::Base
  has_one :person, :as => :person_role, :dependent => :destroy
  belongs_to :user_role, :polymorphic => true
  accepts_nested_attributes_for :person, :allow_destroy => true
end

class Person < ActiveRecord::Base
  has_many :address_person_links, :dependent => :destroy
  has_many :addresses, :through => :address_person_links, :uniq => true, :dependent => :destroy

  belongs_to :person_role, :polymorphic => true

  accepts_nested_attributes_for :addresses, :allow_destroy => true
end

class AddressPersonLink < ActiveRecord::Base
  belongs_to :address
  belongs_to :person
end

class Address < ActiveRecord::Base
  has_many :address_person_links, :dependent => :destroy
  has_many :people, :through => :address_person_links, :uniq => true
end

when I call @employee.update_attributes(params[:employee]) from my controller it updates everything except the address. However if I raise params.inspect and copy that into a variable in script/console, it DOES work. Example:

>> e = Employee.find(8)
=> #<Employee id: 8, active: true, admin: false, created_at: "2010-10-06 20:05:01", updated_at: "2010-10-06 20:11:20">
>>address = a.user.person.addresses[0]
=> #<Address id: 10, address1: "225 3rd Ave", address2: "", address3: "", city: "Sacramento", state_id: 5, zip_code: "95814", country_id: 1, contact_type_id: 2, created_at: "2010-10-06 20:05:01", updated_at: "2010-10-06 22:40:06">
>> params = {"commit"=>"Update",
?>  "_method"=>"put",
?>  "authenticity_token"=>"sYgfNDbt4SB00WSjJXnpF4FNhRT4HBHcY7W+IENpC/k=",
?>  "id"=>"8",
?>  "employee"=>{"user_attributes"=>{"person_attributes"=>{"addresses_attributes"=>{"0"=>{"address1"=>"225 3rd Ave Suite 777",
?>  "city"=>"Sacramento",
?>  "contact_type_id"=>"2",
?>  "address2"=>"",
?>  "address3"=>"",
?>  "zip_code"=>"95814",
?>  "country_id"=>"1",
?>  "id"=>"10",
?>  "state_id"=>"5"}},
?>  "prefix"=>"",
?>  "email_addresses_attributes"=>{"0"=>{"contact_type_id"=>"2",
?>  "id"=>"16",
?>  "email"=>"first@example.com"}},
?>  "id"=>"16",
?>  "last_name"=>"Last",
?>  "suffix"=>"",
?>  "phone_numbers_attributes"=>{"0"=>{"number"=>"9165555555",
?>  "contact_type_id"=>"1",
?>  "extension"=>"",
?>  "id"=>"16"}},
?>  "first_name"=>"First"},
?>  "password_confirmation"=>"321321",
?>  "id"=>"16",
?>  "password"=>"321321",
?>  "login"=>"third"},
?>  "admin"=>"0",
?>  "active"=>"1"}}
=> # this outputs the hash that was created
>> e.update_attributes(params["employee"]) # they are no longer symbols but string keys now
=> true
>> address
=> #<Address id: 10, address1: "225 3rd Ave Suite 777", address2: "", address3: "", city: "Sacramento", state_id: 5, zip_code: "95814", country_id: 1, contact_type_id: 2, created_at: "2010-10-06 20:05:01", updated_at: "2010-10-06 22:40:16">

So you can see the address was updated from script/console but not from my controller.

If this is information overload, then the simple version of this question is:
Why doesn’t my address get updated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:31:00+00:00Added an answer on May 17, 2026 at 6:31 pm

    I was able to finally look at this problem today. It was a quick fix that I stumbled upon because I was dealing with another issue: addresses weren’t being deleted when I deleted Employees, Users or People. The fix is this:

    class AddressPersonLink < ActiveRecord::Base
      # some how adding dependent => destroy fixed the problem
      # i was having with updating as well.
      belongs_to :address, :dependent => :destroy
      belongs_to :person
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.