Saving a related object


I have two models. A and B. A belongs_to B (and B has_one A). I have one
for creating both an A and a B, so I do:

a =[:a])
a.b =[:b])

and it works as intended, both objects get saved, or none, validation
But then I have the page to edit these objects. So I do:

a = A.find(a_id)
…latter on…
a.attributes = params[:a]
a.b.attributes = params[:b]

and there it is where it breaks. b seems to be never saved. I’m not sure
if it
is validated or not. What should I do to cascade the saves? or how
should I
save these two objects?

Thank you.

J. Pablo Fernández [email protected] (

Did you look at

after_save ?

Maybe you can perform something inside it in the A model