我正在尝试使用aasm ruby gem和rails将参数传递到我的事件中。但是,每当我尝试按照文档中的示例操作时,都会得到错误Wrong number of arguments. Expected 0, got 2.。我做错了什么?
代码如下:
class Foo < ActiveRecord::Base
include AASM
aasm column: :status do
state :stopped, initial: true
# TODO: if post fails, should this remain in_progress?
state :running
event :run, aasm_fire_event: :do_something do
transitions from: :stopped, to: :running
end
end
def do_something(list_of_things)
.... #stuff here
end
end然后调用代码
foo = Foo.new
foo.run(:running, [param1, param2]) 这看起来跟示例一样,但我不能让它工作。任何帮助都将不胜感激。
发布于 2016-10-11 01:43:08
对于遇到此问题的任何人,如果您的事件或将在事件中调用的old_state或new_state上有其他回调,则上面的模式将尝试将参数应用于所有回调。这就是发生在我身上的事情,所以我解决了这个问题,允许在这些回调上传递参数,然后不对它们做任何事情。
https://stackoverflow.com/questions/39924902
复制相似问题