这就是我所拥有的:
state_machine :state, :initial => :open do
after_transition :on => :buy, :do => :send_buy_notification_email
after_transition :on => :take, :do => :send_take_notification_email
after_transition :on => :accept, :do => :send_accept_notification_email
after_transition :on => :cancel, :do => :send_cancel_notification_email
现在我想在初始状态打开时触发:send_trade_notification_email。
我该怎么做?
干杯,
乔尔
答案 0 :(得分:3)
由于状态转换类似于“通常的”AR回调,也许你的方法应该在after_create回调中触发?毕竟,你的过渡是从零到开放,这将在创建时发生:
after_create :send_trade_notification_email
如果允许的话,将完成同样的事情:
after_transition :on=>:create, :do=>:send_trade_notification_email
答案 1 :(得分:0)
我找到了另一种方法
def initial_send_trade_notification_email
send_trade_notification_email #do what you need on create
:open # return initial state
end
state_machine initial: lambda(&:initial_send_trade_notification_email) do
#...
end