views:

129

answers:

1

Is it possible to access the collection of states for the given model:

class Conversation include 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

end

I would like to be able to get an array of states like:

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

Is this possible?

+1  A: 

The AASM gem has two class methods that return a collection of states for a given model:

  aasm_states
  aasm_states_for_select

For instance:

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
rswolff