如何访问特定 Rails 模型的 acts_as_state_machine 状态集合?

发布于 2024-08-07 07:30:16 字数 438 浏览 8 评论 0原文

是否可以访问给定模型的状态集合:

Conversation 类 包括 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

我希望能够获得一系列状态,例如:

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

这可能吗?

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?

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

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

发布评论

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

评论(1

赤濁 2024-08-14 07:30:16

AASM gem 有两个类方法,它们返回给定模型的状态集合:

  aasm_states
  aasm_states_for_select

例如:

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

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