Read more

ActiveRecord 2.3: Nested attribute changes disappear

Tobias Kraze
February 11, 2013Software engineer at makandra GmbH

There is a bug in ActiveRecord 2.3.x that leads to changes in nested forms getting lost.

class Project < ActiveRecord::Base
  has_many :tasks
  accepts_nested_attributes_for :tasks
end
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

If you access project.tasks after setting tasks through the nested attribute logic, all tasks will be reloaded and all changes will be lost. This usually happens

  • in validations
  • in callbacks
  • after validation errors, when rendering the view again

The attached initializer fixes those issues.

Posted by Tobias Kraze to makandra dev (2013-02-11 18:06)