1

我是 AASM 的新手,并试图获取 MyModel 模型中可以转换为状态的所有状态的列表:newstate。

因此,例如:

  aasm_event :finish do
    transitions :to => :finalstate, :from => [:start, :working]
  end

基本上,我想通过模型返回 [:start, :working] 数组,所以类似于

MyModel.aasm_events.finish.transitions.from

但是,好吧,这不是语法......我在文档中找不到任何东西。

任何建议表示赞赏。

4

1 回答 1

2

直到现在它才被支持。新发布的gem 版本 3.0.12现在支持一个名为aasm_from_states_for_state的类方法,它完全符合您的要求。不幸的是,您建议的小 DSL (...finish.transitions.from) 非常好,但目前不可用。但我会记住的;)

像这样使用新的类方法:

MyModel.aasm_from_states_for_state(:finalstate)

它返回所有可能的状态。如果您只想要特定转换的 from 状态:

MyModel.aasm_from_states_for_state(:finalstate, :transition => :finish)

或更现代(使用 Ruby 1.9)

MyModel.aasm_from_states_for_state(:finalstate, transition: :finish)

所有调用都从状态返回一个可能的数组。

于 2012-10-19T10:12:28.327 回答