문제

Worflow is a state machine ruby gem. Here is a code example from its document on github:

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

Gem workflow is added to the model Article. Here are 2 questions:

  1. Where the gem workflow save article state data? In Rails app's database?. Assume workflow is integrated into a rails app. Or question could be more generic: how gem workflow saves article state data?
  2. by adding workflow to model article, does it add more columns to table article for state data storage? If it does, when this change of table structure happens?
도움이 되었습니까?

해결책

I think if you want the workflow gem to save to the database, you have to create a string field column in your table called workflow_state (see Integration with ActiveRecord)

class AddWorkflowToArticlesTable < ActiveRecord::Migration
  def change
    add_column :articles, :workflow_state, :string
  end
end

Something that like should work, and then article.state should reflect what's saved in the database

Hope this helps

다른 팁

In memory. If the option is selected, also to a database via Active Record.

From: https://github.com/geekq/workflow - about 1/3 of the way down.

Integration with ActiveRecord

Workflow library can handle the state persistence fully automatically. You only need to define a string field on the table called workflow_state and include the workflow mixin in your model class as usual:

class Order < ActiveRecord::Base
  include Workflow
  workflow do
    # list states and transitions here
  end
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top