Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo state machines in Single ruby class
    primarykey
    data
    text
    <p>Following are System Specifications :=</p> <ul> <li>Language Ruby</li> <li>Framework Padrino</li> <li>ORM Mongoid</li> <li>Database MongoDB</li> </ul> <p>Now I have a Person model with two fields tat maintain states separately.</p> <pre><code>class Person include Mongoid::Document include Mongoid::Timestamps # Field Names #----------------- field :name, :type =&gt; String field :sms_state, :type =&gt; String, :default =&gt; 'main_menu' field :ivr_state, :type =&gt; String, :default =&gt; 'main_menu' end </code></pre> <p>I add State Machines using Monkey Patching, as I need to Update the State as per request controller. ie, If SMS Controller is requested then only SMS State Machine for sms_state should Monkey Patched and similarly for IVR Controller I do Monkey Patching this way, (Reason for Monkey PAtching as the entire flow and states of State Machine are same except the State Field, and Events Change...) </p> <pre><code>Person.class_eval do state_machine :state_field, :initial =&gt; :main_menu do # State Machine Flow # Events Details #=============================================================== event :state_reset do transition all - [:country_confirmation, :topup_confirmation] =&gt; :main_menu end event :country_list do transition [:main_menu, :did_purchased, :country_probed] =&gt; :country_listed end # States Details #=============================================================================== state :main_menu do define_method (:get_msg) {|obj| current_module.get_main_menu_msg(obj.dids.count, obj.spokn_id) } end state :country_listed do define_method (:get_msg) {|obj| current_module.get_country_list_msg Country.all } end end end </code></pre> <p>But It Works Fine for State Machine only. Suppose it was working Fine for SMS Controller, and If request comes from IVR Controller the Ivr State Machine is Monkey Patched. But State Field Doesn't and I get following ERROR</p> <pre><code>StateMachine::InvalidTransition - Cannot transition sms_state via :ivr_country_list from :country_listed </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload