带有state_machine gem的Rails应用程序"未定义的方法' state_paths' ..."

时间:2011-03-15 20:03:17

标签: ruby-on-rails-3 activerecord state-machine

在Rails 3应用程序中,我有以下内容:

class Kase < ActiveRecord::Base
  state_machine :state, :initial => :lead do
    state :lead
    state :active
    state :completed

    event :reset_status do
      transition any => :lead
    end

    event :activate do
      transition any => :active
    end

    event :complete do
      transition any => :completed
    end
  end
end

文档(https://github.com/pluginaweek/state_machine)显示以下内容适用于我的情况:

vehicle.state_paths # => [[#<StateMachine::Transition ...], [#<StateMachine::Transition ...], ...]
vehicle.state_paths.to_states # => [:lead, :active, :completed]

但是,当我运行以下操作时出现错误:

@kase = Kase.first
@kase.state
  => "lead"
@kase.state_paths
  NoMethodError: undefined method `state_paths' for #<Kase:0x00000100d95ca0> ...

我正在尝试获取Kase所有可能状态的列表。我错过了什么?

1 个答案:

答案 0 :(得分:0)

state_paths在state_machine的已发布版本中不可用。本周将发布一个新版本,其中包括您尝试使用的功能。