是否可以访问给定模型的状态集合:
班级对话 包括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']
这可能吗?
答案 0 :(得分: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