Saving ActiveRecord objects that are composed of other objec

I’ve got two pretty simple model objects Page and PagePart. Page
has_many PageParts and PageParts belong_to Pages.

When updating PageParts for a specific Page I’d like to be able to do:[x].content = ‘changed’

and expect that should the validation pass the changed page part would
be saved as well, but this doesn’t seem to work for me. Why doesn’t
ActiveRecord automatically update objects that are composed of other
objects when saving?

I’d rather not write:

if { }

because should a failure occur when saving the parts I don’t want the
page to be saved. Of course I could override the #save method and use
transactions for this, but I’d rather not do that if ActiveRecord
provides something built in. Am I missing something?

John L.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs