4

I develops Ruby on Rails application and now looking for workflow gem that allows configure states without any programming.

I found some gems: rails_workflow, state_machine, workflow.

But as I understood, these gems assumes that states will be hard-coded, eg workflow gem states:

class Article
  include Workflow
  workflow do
    state :new do
      event :submit, :transitions_to => :awaiting_review
    end
    state :awaiting_review do
      event :review, :transitions_to => :being_reviewed
    end
    state :being_reviewed do
      event :accept, :transitions_to => :accepted
      event :reject, :transitions_to => :rejected
    end
    state :accepted
    state :rejected
  end
end

I need that my application users states could configure states and transitions conditions theyself, without developer.

Redmine already has this feature, but it's ready system, not gem that I can connect to my application

Are there any gems with such features?

General Failure
  • 2,421
  • 4
  • 23
  • 49
  • Would love to know any solutions to this; I could write an answer with ideas but I've not found a gem – Richard Peck Feb 17 '16 at 10:40
  • 2
    You can work on this solution, I found it promising on reading it but I think this solution can be extended to any use: http://stackoverflow.com/questions/14349141/how-do-i-create-dynamic-definitions-for-state-machine-based-on-user-defined-data – Jagjot Feb 21 '16 at 05:42
  • I would not recommend the `workflow` gem... I inherited a legacy app that uses it, and I've found it to be buggy—not surprising, since it is no longer maintained. I have used `AASM` before and not had any problems, although it's not designed for database-based workflows. I have not used `rails_workflow` but it claims to already support user-configurable workflows. – iconoclast Feb 21 '18 at 19:22

3 Answers3

5

I devised the following solution from my comment earlier. Use the gem state_machine, and then you can define the transitions of your state machine using ActiveRecord like this:

Define a Transition model with columns, 'to', 'from' and 'on'. They all will have string as their data-type.

The states will be defined as follows:

Transition.create(:from => "parked", :to => "idling", :on => "ignite")

After this you need to modify your transitions method as follows:

def transitions
  transitions_data = []
  Transition.all.each do |transition|
    transitions_data << { transition.from.to_sym => transition.to.to_sym, :on => transition.on.to_sym }  
  end
  transitions_data
end

Obviously if you have more than one machine you can have some other column like 'machine_name' and store the machine name there and fetch only those rows.

As the original person who answered this said "This is just one example, and could be much further optimized. I'll leave that part to you. Hopefully this will give you a good start."

I hope this points you in the correct direction.

Source:

SO and state_machine Gem

Community
  • 1
  • 1
Jagjot
  • 5,816
  • 2
  • 24
  • 41
2

rails_workflow gem is not about states :)

Most state transition engines uses states to simulate process configuration which is wrong by nature. If some application have process (meaning business logic process with different operations, user operations, tasks etc) - then it should use process management and most of gems with states-to-states transition uses state transitions just to roughly simulate workflow.

There is lots of disadvantages of states transition logic so again - rails_workflow is not about states :) It's about process configuration, monitoring and controlling.

Max
  • 341
  • 2
  • 6
1

You can copy redmine , or build your own service object with ease using this gem :

Waterfall

It's a brand new gem , i met his author in RubyLille this week. it'a way to elegantly chain callback-like methods and get errors managed by rails , you can build a robust state machine with this .

plombix
  • 396
  • 3
  • 13
  • How will OP define states from database in `Waterfall`, an example could help. – Jagjot Feb 22 '16 at 06:24
  • I'm not shure i clearly understand your question , and traduce me "OP" please . – plombix Feb 22 '16 at 21:08
  • What I mean to say is, how can we define states without doing actual coding in `Waterfall`. OP wants to define states from database and I did not see that in Waterfall or maybe I missed something so I asked you for an example. – Jagjot Feb 23 '16 at 06:58
  • 1
    @plombix, OP translates as original poster – Aaron Washburn Feb 23 '16 at 14:04
  • i did not understood that, i thought it was an code's aesthetic matter . waterfall make an elegant structure to support models's validations and methods/scopes it will not defines states on his own , my bad – plombix Feb 28 '16 at 16:18