Passing variables to Rails StateMachine gem transitions

前端 未结 5 2145
猫巷女王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:59

    I don't think you can pass params to events with that gem, so maybe you could try storing the current_user on @car (temporarily) so that your audit callback can access it.

    In controller

    @car.driver = current_user
    

    In callback

    after_crash do |car, transition|
       create_audit_log car.driver, transition
    end
    

    Or something along those lines.. :)

提交回复
热议问题