dvictory/her — pull request #4 by sdrioux (2014-05-20 23:07:16+00:00)
Title: Fix association bug

When editing an item that does not have a recipe, Her looks for the recipe association in the item object to determine if it needs to fetch it. Because we're passing item: { recipe: nil }, it checks nil.empty? , which causes an error. Changing this:

@parent.attributes[:recipe].empty?

to this: @parent.attributes[:recipe].nil? || @parent.attributes[:recipe].empty?
catches the error.

Then we have a newly instantiated recipe. Because a recipe has_many ingredients, Her then tries to fetch the recipe's ingredients. It checks if @parent.attributes.include?(:ingredients). Because that returns false, it builds the association path for returning ingredients and tries to fetch the ingredients from the server, which is not a valid endpoint. If we add @parent.attributes.empty? to the beginning of our if statement, it will recognize that this the recipe is a blank object, and just add an empty association to the recipe.