0

我正在使用aasm状态机。我有以下事件。这样做是将状态从 更改order_createdpayment_response_received。所以在改变这个之后我想调用一个方法verify_payment_response(data)。我可以通过调用来改变这种状态@booking.move_to_payment_response_received!,但是如何传递参数以在 after 回调中使用?

event :move_to_payment_response_received do
  after_commit do
         self.verify_payment_response(data) #How can I pass this data param from my controller
  end
  transitions from: :order_created, to: :payment_response_received
end
4

1 回答 1

4

您可以data在触发事件之前将 分配给局部变量:

# in your model

attr_accessor :payment_response_data

event :move_to_payment_response_received, :after_commit => :verify_payment_response do
  transitions from: :order_created, to: :payment_response_received
end

private

def verify_payment_response
  data = payment_response_data

  # already existing code to verify `data`
end

并在您的控制器中使用它,如下所示:

@booking.payment_response_data = data
@booking.move_to_payment_response_received!
于 2017-10-15T08:01:12.610 回答