It’s been a frustrating night trying to figure out how accepts_nested_attributes_for, autosave, dirtyness, and Rails versions all fit together. Going to try and summarize my findings and hopefully I’ll get it right.
- accepts_nested_attributes_for turns on autosave
- autosave will cause any loaded associations to be saved when save for the parent object is called
- the key word is “loaded”, so a find with an include will cause the association to be loaded, and thus autosaved (took my a long time to track this down)
- in Rails 2.3.5 the association is saved regardless of dirty state
- in Rails 2.3.8 the association is saved only if dirty