2014-01-27 48 views
0

無法理解通過我收到此錯誤StateMachine :: InvalidTransition:無法通過transition_details_not_found從新:(原因(S) :國家不能通過「找不到退款詳情」)過渡無法從新狀態過渡 - 等待退款詳細信息狀態Rails Statemachine Gem --- Pluginaweek

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 

我打電話之前的過渡保存

+0

只是把它清除掉,你正在做'object.refund_details_not_found'和得到那個錯誤? – amencarini

+0

@amencarini是的 – chirag7jain

回答

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 S,超執行state_machine已經等

+0

我試圖在保存塊之前做到這一點。在那裏與狀態機轉換和保存之前有一些衝突 – chirag7jain

+0

在同一個對象的'before_save'中?我會建議使用'pry' gem,並在'before_save'中放一個'binding.pry'來查看會發生什麼。 – amencarini