无法从新的状态转换 - 等待退款详情状态Rails Statemachine Gem --- Pluginaweek

时间:2014-01-27 11:24:10

标签: ruby-on-rails ruby state-machine

无法理解通过我收到此错误StateMachine :: InvalidTransition:无法通过以下方式转换状态:refund_details_not_found from:new(原因:状态无法通过“未找到退款详情”转换)

state_machine :initial => :new do    
    event :all_products_received do
      transition [:new, :pending_refund_details, :canceled] => :pending_payment
    end

event :refund_details_not_found do
  transition :new => :pending_refund_details
end

event :order_return_canceled do
  transition :new => :canceled
end

event :mistaked_canceled do
  transition :canceled => :buyer_dispatched
end

event :payment_made do
  transition :pending_payment => :payment_complete
end

before_transition :to => :canceled do |return1|
  return1.total = 0
end

before_transition :to => :pending_payment do |return1|
  return1.pending_on = Time.now
end

before_transition :to => :payment_complete do |return1|
  return1.completed_on = Time.now
end

end

我在保存之前调用转换

1 个答案:

答案 0 :(得分:0)

我已经测试了您的代码,并且我自己没有收到任何错误:

require 'state_machine'

class Thing
  attr_accessor :state

  state_machine :initial => :new do
    event :refund_details_not_found do
      transition :new => :pending_refund_details
    end
  end
end

t = Thing.new
puts t.state
#=> new
t.refund_details_not_found
puts t.state
#=> pending_refund_details

我建议检查是否有其他元素干扰,例如:Rails验证,其他回调或before_transition,已经实现state_machine的超类等。