0

是否可以访问给定模型的状态集合:

课堂对话包括AASM

aasm_initial_state :unread

aasm_state :unread
aasm_state :read
aasm_state :closed

aasm_event :view do
  transitions :to => :read, :from => [:unread]
end

aasm_event :close do
  transitions :to => :closed, :from => [:read, :unread]
end

结尾

我希望能够获得一系列状态,例如:

['unread', 'read', 'closed']

这可能吗?

4

1 回答 1

1

AASM gem 有两个类方法,它们返回给定模型的状态集合:

  aasm_states
  aasm_states_for_select

例如:

class Note < ActiveRecord::Base
  aasm_initial_state :unread

  aasm_state :unread
  aasm_state :read
  aasm_state :closed

  aasm_event :view do
    transitions :to => :read, :from => [:unread]
  end

  aasm_event :close do
    transitions :to => :closed, :from => [:read, :unread]
  end 
end

> Note.aasm_states
> Note.aasm_states_for_select
于 2009-10-02T03:24:06.070 回答