在模型的不同列上实现多个不同的aasm实现

时间:2012-10-01 09:57:04

标签: ruby-on-rails-3

我有一个模型如下

class Inspection < ActiveRecord::Base
  include AASM

  aasm_column :status  #aasm in 'status' field
  aasm_initial_state :new
  aasm_state :new
  aasm_state :inprocess
  aasm_state :complete
  aasm_state :approved

  aasm_event :inprocess do
    transitions :to => :inprocess, :from => :new
  end

  aasm_event :complete do
    transitions :to => :complete, :from => :inprocess
  end

  aasm_event :approve do
    transitions :to => :approved, :from => :complete
  end


  aasm_column :sharing_status  #aasm in 'sharing_status' field
  aasm_initial_state :not_shared
  aasm_state :not_shared
  aasm_state :shared
  aasm_state :revoked

  aasm_event :share do
    transitions :to => :shared, :from => :not_shared
  end

  aasm_event :revoke do
    transitions :to => :revoked, :from => :shared
  end

  .....
end

我想在检查的两个不同模型字段上实现不同的aasm状态和转换。第一个转换在上面的代码中不起作用(如果存在第二个状态和转换)。怎么解决这个问题?

1 个答案:

答案 0 :(得分:1)

我有同样的问题 似乎AASM不支持在同一模型上拥有多个状态模型,但插件'state_machine'确实支持此功能。

https://github.com/pluginaweek/state_machine