Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

chaining transitions together

25 views
Skip to first unread message

Roger Smith

unread,
Feb 27, 2013, 10:42:42 PM2/27/13
to pluginaw...@googlegroups.com
Is it possible to chain transitions to create a workflow?

For example

  state_machine :state, :initial => :initialized do

  event :find_item do
  transition :initialized => :finding_item
  end

    after_transition :initialized => :finding_item do |order, trans|
      if product = Item.find(12)
         transition :finding_item => :item_found
      else
         transition :finding_item => :item_not_found
      end
    end

  after_transition :finding_item => :item_not_found do |order, trans| 
      #email item not found
   end

Bill Burcham

unread,
Mar 6, 2013, 9:33:43 AM3/6/13
to pluginaw...@googlegroups.com
Close. You could do this:

event :item_found do
   transition :finding_item => :item_found
end
event :item_not_found do
   transition :finding_item => :item_not_found
end
...
if product = Item.find(12)
   order.item_found
else
   order.item_not_found
end

I used event names that match the state names which I feel is generally a bad practice, or at least a side-effect of a bad design. But you get the idea.
Reply all
Reply to author
Forward
0 new messages