0

My event signature is

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

on transition callback is

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

and called as

ride.accepted(driver)

yet I get the error:

Event 'accepted' cannot transition from 'created'

why would this be so? Removing the on_transition callback allows the transition to proceed. I would like to pass values to the on_transition callback.

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
deepwinter
  • 4,568
  • 2
  • 31
  • 37
  • The [documentation](https://github.com/aasm/aasm) uses a `Proc` for the `on_transition`, or is there some other way to define it? – Buck Doyle May 24 '14 at 02:01
  • also docs say that Proc is no longer necessary to define on_transition, it can defined with :symbol, which works for the other callbacks. I don't think the using Proc would make a difference, but could I be wrong about that? – deepwinter May 24 '14 at 02:36
  • Oh, I don’t see that. I can’t be sure, but I suspect the problem is that the method is being called without arguments. But I don’t understand why they pass two parameters in the documentation and the method only receives one. So… I’m no help, I think! – Buck Doyle May 24 '14 at 02:42
  • the docs contain a deprecated form where the current state needed to be passed as the first argument (this has been removed from the current implementation) i tried this too, and got the same error. – deepwinter May 24 '14 at 03:15
  • looks like the problem may be a misunderstanding on my side.. according to the docs, callbacks are registered with the event, not with the transitions within an event. – deepwinter May 27 '14 at 22:15
  • Which version of AASM are you using? Using :on_transition with a transition is totally fine, but if you want to provide the driver with the event trigger, as an argument to the :on_transition callback, you have to call accepted(nil, driver). This is cumbersome and I removed it in AASM version 4 (which is not yet released). – alto May 28 '14 at 18:58
  • 1
    ah maybe that is the problem. I read that the extra nil param had been removed, but thought it was already released. – deepwinter May 28 '14 at 23:12
  • yup needed the nil param. – deepwinter Jul 03 '14 at 00:44

0 Answers0