Passing variables to Rails StateMachine gem transitions

前端 未结 5 2139
猫巷女王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 10:57

    I was having trouble with all of the other answers, and then I found that you can simply override the event in the class.

    class Car
      state_machine do
        ...
        event :crash do
          transition any => :crashed
        end
      end
      def crash(current_driver)
        logger.debug(current_driver)
        super
      end
    end
    

    Just make sure to call "super" in your custom method

提交回复
热议问题