Trailblazer error when running operation: "NoMethodError: undefined method `has_key?' for nil:NilClass"

1.1k Views Asked by At

When I try to run a Create operation with the trailblazer gem, I get this error:

NoMethodError: undefined method `has_key?' for nil:NilClass
1

There are 1 best solutions below

1
On

The problem was I wasn't including the name of the model as the root key for the hash being passed to the create operation. That is, I was calling it like this:

ModelClass::Create.run(some_attribute: 'attr', another_attribute: 'other_attr')

when I should have been passing:

ModelClass::Create.run(model_class: {some_attribute: 'attr', another_attribute: 'other_attr'})