我正在使用这个状态机来管理一个Invite对象的" state“属性
https://github.com/pluginaweek/state_machine
我想有一个send_invite方法,它将状态设置为“正在发送”,发送invite,然后将状态设置为"sent“或"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 谢谢
发布于 2012-03-22 02:31:21
状态机是为了在一系列无状态web请求上提供虚拟“状态”而构建的。由于您在一个请求中完成了所有这些操作,因此没有必要使用如此繁重的东西--但如果您更喜欢使用它,它应该可以工作。
https://stackoverflow.com/questions/9810619
复制相似问题