The amazing thing about this is that I somehow didn't catch it before the book came out.
Anyway, what's happening here is a common mistake in parent/child relationships...
When you submit the recipe form, the text of the ingredients is in the
field, which is then set using the method
Code:
recipe#ingredient_string
, which parses the strings and then adds them to the to the ingredient list [code]self.ingredients << ingredient[code]. The problem is that the original ingredients are still there, so the new ones are added on top of the originals, in effect duplicating the ingredients.
The workaround would be to start the
Code:
recipe#ingredient_string
method with something like
Code:
recipe.ingredients.clear
, but you'd want to put that in some kind of transaction block so that the ingredients aren't deleted incorrectly.
Sorry for the wait, hope this helps.