Joe Sak |
Chicago ✈ Montreal |
After ignoring failing tests for weeks for a record that wasn’t saving because the fields for a child association were blank, I finally wrapped my head around the solution.
I’m using accepts_nested_attributes_for :child, :reject_if => :all_blank, which I thought was enough. Reject the empty attributes and don’t attempt to validate it, right?
Well, I finally looked and saw in the development log that its parameters included a hidden field “_delete” which was passing the value “false”. So they weren’t “all_blank”.
Replacing :all_blank with Proc.new { |foo| foo[‘bar’].blank? and foo[‘baz’].blank? } solved it.