Passing variables to Rails StateMachine gem transitions

前端 未结 5 2136
猫巷女王i
猫巷女王i 2021-02-05 10:07

Is it possible to send variables in the the transition? i.e.

@car.crash!(:crashed_by => current_user)

I have callbacks in my model but I nee

5条回答
  •  别跟我提以往
    2021-02-05 11:03

    If you are referring to the state_machine gem - https://github.com/pluginaweek/state_machine - then it supports arguments to events

    after_crash do |car, transition|
      Log.crash(:car => car, :driver => transition.args.first)
    end
    

提交回复
热议问题