dm-accepts_nested_attributes
dm-accepts_nested_attributes copied to clipboard
Error - options_for_nested_attributes is empty hash
I'm getting the following exception when trying to assign nested attributes for a new parent record:
undefined method '[]' for nil:NilClass
This doesn't happen when updating an existing parent record with nested attributes.
The application trace identifies this line in my controller: @contract.attributes = params[:contract]
The error originates here: /lib/dm-accepts_nested_attributes/resource.rb:270:in 'reject_new_record?'
That line looks like this:
guard = self.class.options_for_nested_attributes[relationship.name][:reject_if]
The problem appears to be that self.class.options_for_nested_attributes is an empty hash, so [relationship.name] returns nil, and nil[:reject_if] raises undefined method '[]' for nil:NilClass.
I'm using this gem at commit 09a9eff815.
I don't know whether self.class.options_for_nested_attributes should contain anything or not. Is this something I'm supposed to set? I don't see anything about it in the README.
The following pull request fixes the issue for me. I'm not sure if it fits with your design, however. Feedback?
https://github.com/snusnu/dm-accepts_nested_attributes/pull/13