state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Object attributes that are updated in before_transition are not persisted in other transition callbacks #75

Closed vanboom closed 4 years ago

vanboom commented 4 years ago
   before_transition to: [:shipped] do |order, transition|
      order.ship_date = Time.now
   end

   after_transition to: [:shipped, :picked_up] do |order, transition ||vehicle, transition|
      puts order.ship_date
      order.update_inventory_status!
    end

In this example, the ship_date attribute of the order will be nil in the after_transition callback.

vanboom commented 4 years ago

Please forgive - I had a before_save callback that was meddling. The transition callbacks work perfectly.