Rails AASM(作为状态机)on_transition回调块转换

时间:2014-05-24 01:42:43

标签: ruby-on-rails ruby aasm

我的活动签名是

event :accepted do
  transitions :from => :created, :to => :scheduled, :on_transition => :driver_accepted_ride, :after => :notify_scheduled
end
转换回调

def driver_accepted_ride( driver )
  Rails.logger.debug 'on transition driver accepted ride'
  self.driver = driver 
  self.car = driver.car
  save   
end

并称为

ride.accepted(driver)

然而我收到了错误:

Event 'accepted' cannot transition from 'created'

为什么会这样?删除on_transition回调允许转换继续进行。我想将值传递给on_transition回调。

0 个答案:

没有答案