Rails 应用程序与 state_machine gem 获取“未定义的方法“state_paths”...”
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.