November 19th, 2015
(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: email@example.com
Last winter made fun of a Python team for wasting time trying to figure out how to handle deeply nested relations. They were slowly groping their way toward a graph database solution, which seems to be the route that most end up taking, given enough years and enough pain. This seems to be an area where Object Oriented Programming clearly fails.
And yet, many smart folk continue to try. Ruby’s Reform:
After validation, you have two choices: either call #save and let Reform sort out the rest. Or call #sync, which will write all the properties back to the model. In a nested form, this works recursively, of course.
It’s then up to you what to do with the updated models – they’re still unsaved.
The easiest way to save the data is to call #save on the form.
@form.save #=> populates album with incoming data
# by calling @form.album.title=.
# handle validation errors.
This will sync the data to the model and then call album.save.
Sometimes, you need to do saving manually.