highrise
highrise copied to clipboard
422 Unprocessable Entity on update due to nested models
When updating a Deal, if a nested Party model is included in the post body, a 422 error is being returned.
According to this message, Highrise has recently started returning 422 errors in cases where it hadn't before.
Testing manually, I found this to work fine
<deal>
<name>Deal</name>
</deal>
While this 422'd
<deal>
<name>Deal</name>
<party>
</party>
</deal>
I got around it for my immediate needs by monkey-patching the Deal class as follows, but there's surely a more elegant solution to be had.
module Highrise
class Deal
def encode_with_nested_attribute_exclusion(options={})
encode_without_nested_attribute_exclusion({:except => [:party, :parties]}.merge(options))
end
alias_method_chain :encode, :nested_attribute_exclusion
end
end
Can you write a test to address this issue?
I had the same issue, thanks for the monkey-patch!