I have a Reform::Form::Module where I'm using unnest. If I try to include it more than once I get an error on startup: gems/disposable-0.4.7/lib/disposable/twin/property/unnest.rb:14:in `unnest': undefined method `[]' for nil:NilClass (NoMethodError)
A setup similar to this:
module Contract::Component
module Foo
include Reform::Form::Module
property :foo do
property :bar
end
unnest :bar, from: :foo
end
end
module Contract
class Create < Reform::Form
include Component::Foo
end
end
module Contract
class Update < Reform::Form
include Component::Foo
end
end
This is the relevant part of the code in disposable
def unnest(name, options)
from = options.delete(:from)
# needed to make reform process this field.
options = definitions.get(from)[:nested].definitions.get(name).instance_variable_get(:@options) # FIXME.
options = options.merge(virtual: true, _inherited: true, private_name: nil)
property(name, options)
delegates from, name, "#{name}="
end
Since unnest is a class method, options.delete(:from) will actually delete the key from the method argument itself, causing each subsequent call to fail.
Changing that line to from = options[:from] seems to fix the issue for me, without introducing any noticeable side-effects.
I have a Reform::Form::Module where I'm using unnest. If I try to include it more than once I get an error on startup:
gems/disposable-0.4.7/lib/disposable/twin/property/unnest.rb:14:in `unnest': undefined method `[]' for nil:NilClass (NoMethodError)
A setup similar to this:
This is the relevant part of the code in disposable
Since unnest is a class method,
options.delete(:from)
will actually delete the key from the method argument itself, causing each subsequent call to fail. Changing that line tofrom = options[:from]
seems to fix the issue for me, without introducing any noticeable side-effects.