2012-03-21 1 views
2

を送る使います招待し、状態を「送信済み」または「could_not_send」に設定するとエラーが発生します、私は「送信」するセットに状態をsend_invite方法を持っていると思います招待オブジェクト</p> <p><a href="https://github.com/pluginaweek/state_machine" rel="nofollow">https://github.com/pluginaweek/state_machine</a></p> <p>の「状態」属性を管理するには、このステート・マシンを使用していstate_machine

状態マシンDSLでこれを行うことができるはずですが、間違っていますか?

通常の方法を追加するだけですか?

答えて

0

ステートマシンはステートレスなWeb要求のシリーズを超える仮想「の状態」を提供するために建てられた

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 

感謝。 1回のリクエストでこれをすべて実行しているので、この重いものを使う必要はありませんが、使いたい場合はうまくいくはずです。