开发者

Multiple state machines in one model?

I have a model that represents a registration process, which needs to track the progression of开发者_开发技巧 several processes (background checks, interviews, information collection...). Each one can be represented by a state machine, and then the overall state of the registration might depend on the state of the others.

Can aasm handle this? Any other ideas or design considerations?


Since this question comes up when you google multiple state machines in one model, it would be good to have an answer, although there is already an answer. Please try doing:

class Example < ActiveRecord::Base
 include AASM

    aasm :search, :column => :search do
    state :initialised, :initial => true
    ...
    end  
    aasm :sync, :column => :sync do
    state :unsynced, :initial => true
    ...
    end 
end

This will create two state machines based on two columns, search and sync.


Try this plugin, which you can use to even inherit from other state machines:

http://api.pluginaweek.org/state_machine/


If you need multiple statemachines in one model it's probably getting to big and it's time to split the model. So in your example you should add models for background checks, interviews, information collection...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜