是否可以在转换中发送变量?即
@car.crash!(:crashed_by => current_user)
Run Code Online (Sandbox Code Playgroud)
我在我的模型中有回调,但我需要向他们发送启动过渡的用户
after_crash do |car, transition|
# Log the car crashers name
end
Run Code Online (Sandbox Code Playgroud)
我无法访问current_user,因为我在模型中而不是Controller/View.
在你说之前......我知道我知道.
不要尝试访问模型中的会话变量
我知道了.
但是,每当您希望创建一个记录或审核某些内容的回调时,您很可能想知道是谁造成的?通常我的控制器中有一些东西像...
@foo.some_method(current_user)
Run Code Online (Sandbox Code Playgroud)
我的Foo模型会期望一些用户发起some_method但是我如何通过StateMachine gem转换呢?