2012-03-21 26 views
2

我使用這個狀態機管理上的「狀態」屬性邀請對象使用state_machine

https://github.com/pluginaweek/state_machine

我想有一個send_invite方法設置狀態,以「發送」,發送邀請,然後將狀態設置爲「發送」或「could_not_send」是有一些錯誤

似乎我應該可以在狀態機DSL中做到這一點,我錯了嗎?

或者我應該只是添加一個正常的方法?

state_machine :initial => :pending do 
     event :send do 
      transition :pending => :sending 
     end 

     event :invite_sent do 
      transition :sending => :invited 
     end 

     event :error_sending do 
      transition :sending => :error 
     end  
    end 

    def send_invite 
     send 
     try 
     .... code to send invite... 
     invite_sent 
     catch 
      error_sending! 
     end 
    end 

感謝

回答

0

狀態機的建立是爲了提供虛擬「規定」在一系列無狀態的Web請求。既然你在一個請求中完成了這一切,那麼使用這麼重的東西並不是必須的,但是如果你願意使用它,它應該可以工作。

相關問題