nil:NilClass 的 Trailblazer Operation 未定义方法“调用”
Trailblazer Operation undefined method `call' for nil:NilClass
我有一个简单的开拓者操作如下:
class User::Delete < Trailblazer::Operation
extend Contract::DSL
contract 'params' do
property :token
validates :token, presence: true
end
step Contract::Validate(name: 'params'), before: 'operation.new'
success :kill_zombie
def kill_zombie(options, params:, **)
options['killed'] = true
end
end
当我运行在rails控制台下运行时,输出结果是:
irb(main):003:0> User::Delete.()
NoMethodError: undefined method `call' for nil:NilClass
from (irb):3
如果我删除合同行:
class User::Delete < Trailblazer::Operation
extend Contract::DSL
contract 'params' do
property :token
validates :token, presence: true
end
success :kill_zombie
def kill_zombie(options, params:, **)
options['killed'] = true
end
end
它按预期工作:
irb(main):005:0> User::Delete.()
=> <Result:true <Skill {"killed"=>true} {"params"=>{}} {"pipetree"=>[>operation.new,>kill_zombie], "contract.params.class"=>#<Class:0x0000000003e54e50>}> >
irb(main):006:0>
有什么想法吗?
我会深入研究文档 http://trailblazer.to/gems/operation/2.0/contract.html
该消息表示you are trying to call a method on a nil
object.
对象是User::Delete
,方法是.()
User::Delete.()
User::Delete
可能未定义,因为它没有通过您的验证?
step Contract::Validate(name: 'params'), before: 'operation.new'
只是发帖给你一些意见,我没有解决方案。我会在调用方法之前检查 User::Delete
。
User::Delete
将是 nil
,您需要更改验证或确保正确实例化该对象。
使用改革合同时,您需要在 Contract::Validate
之前 Contract::Build
。使用 Dry
架构,不需要构建步骤。
我有一个简单的开拓者操作如下:
class User::Delete < Trailblazer::Operation
extend Contract::DSL
contract 'params' do
property :token
validates :token, presence: true
end
step Contract::Validate(name: 'params'), before: 'operation.new'
success :kill_zombie
def kill_zombie(options, params:, **)
options['killed'] = true
end
end
当我运行在rails控制台下运行时,输出结果是:
irb(main):003:0> User::Delete.()
NoMethodError: undefined method `call' for nil:NilClass
from (irb):3
如果我删除合同行:
class User::Delete < Trailblazer::Operation
extend Contract::DSL
contract 'params' do
property :token
validates :token, presence: true
end
success :kill_zombie
def kill_zombie(options, params:, **)
options['killed'] = true
end
end
它按预期工作:
irb(main):005:0> User::Delete.()
=> <Result:true <Skill {"killed"=>true} {"params"=>{}} {"pipetree"=>[>operation.new,>kill_zombie], "contract.params.class"=>#<Class:0x0000000003e54e50>}> >
irb(main):006:0>
有什么想法吗?
我会深入研究文档 http://trailblazer.to/gems/operation/2.0/contract.html
该消息表示you are trying to call a method on a nil
object.
对象是User::Delete
,方法是.()
User::Delete.()
User::Delete
可能未定义,因为它没有通过您的验证?
step Contract::Validate(name: 'params'), before: 'operation.new'
只是发帖给你一些意见,我没有解决方案。我会在调用方法之前检查 User::Delete
。
User::Delete
将是 nil
,您需要更改验证或确保正确实例化该对象。
使用改革合同时,您需要在 Contract::Validate
之前 Contract::Build
。使用 Dry
架构,不需要构建步骤。