Rails 应用程序与 state_machine gem 获取“未定义的方法“state_paths”...”

发布于 2024-10-22 06:23:27 字数 1004 浏览 1 评论 0原文

在 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 的所有可能状态的列表。我缺少什么?

In a Rails 3 app I have the following:

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

The documentation (https://github.com/pluginaweek/state_machine) shows that the following should be available for my situation:

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

However, when I run the following I get an error:

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

I'm trying to get a list of all the possible states for a Kase. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思 2024-10-29 06:23:27

state_paths 在 state_machine 的发布版本中尚不可用。新版本将于本周发布,其中包含您尝试使用的功能。

state_paths is not available in a released version of state_machine yet. A new version will be released this week that includes the feature you're trying to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文