1

我有一个模型如下

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

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

4

1 回答 1

1

我有同样的问题,似乎 AASM 不支持在同一模型上拥有多个状态模型,但是插件“state_machine”确实支持这一点。

https://github.com/pluginaweek/state_machine

于 2013-10-14T12:29:29.317 回答