Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby AASM在子类中添加回调_Ruby_Aasm - Fatal编程技术网

Ruby AASM在子类中添加回调

Ruby AASM在子类中添加回调,ruby,aasm,Ruby,Aasm,当AASM在父模型中定义时,是否有方法在子模型中添加回调 class Parent include AASM aasm do state :initialised, :initial => true state :filled_out state :authorised event :fill_out do transitions :from => :initialised, :to => :filled_out e

当AASM在父模型中定义时,是否有方法在子模型中添加回调

class Parent
  include AASM
  aasm do
    state :initialised, :initial => true
    state :filled_out
    state :authorised

    event :fill_out do
      transitions :from => :initialised, :to => :filled_out
    end

    event :authorise, :before => :stamp_it do
      transitions :from => :filled_out, :to => :authorised
    end

    def stamp_it
      puts "Stamped"
    end
  end
end
在子类中,我们要添加回调
邮件\u it
。似乎我们必须从父级重新定义整个
事件
,才能添加另一个回调

class Child < Parent
  aasm do
    event :authorise, :before => [:stamp_it, :mail_it] do
      transitions :from => :filled_out, :to => :authorised
    end
  end

  def mail_it
    puts "Mail it"
  end
end
类子类<父类
aasm do
事件:授权,:before=>[:盖章,:邮寄]do
转换:从=>:填写,:到=>:授权
结束
结束
def邮件
放“邮寄”
结束
结束

您可以更新子类中的事件

class Child

  def initialize
    event = self.class.aasm.events.select{|e| e.name == :authorise}[0]
    event.options[:before] = [:stamp_it, :mail_it]
  end

end