0

我是 Rails 新手,我正在做一个包含此代码的项目

 aasm_column :status
  aasm do
    state :unregistered, initial: true
    state :pending, enter: :enter_pending_state
    state :activated, enter: :enter_activated_state
    state :disabled

    event :register do
      transitions from: :unregistered, to: :pending, guard: :valid?
    end

    event :activate do
      transitions from: [ :unregistered, :pending ], to: :activated
      transitions from: :pending, to: :activated, guard: :valid?
    end

    event :disable do
      transitions from: [ :pending, :activated ], to: :disabled, guard: :valid?
    end

    event :enable do
      transitions from: :disabled, to: :activated, guard: Proc.new { |u| u.activation_code.blank? && u.valid? }
      transitions from: :disabled, to: :pending, guard: Proc.new { |u| !u.activation_code.blank? && u.valid? }
    end
  end

before_create :enter_pending_state, if: Proc.new{|u|  u.pending? }

aasm_column 是什么意思,这样做的陈词滥调是什么

4

1 回答 1

0

它用于“aasm”gem,您的情况 aasm_column:status 覆盖了 aasm gem 的默认列,即 col 名称为“state”

在这种情况下,我们使用默认列 (aasm_state) 来存储当前状态。但是您很容易在 aasm 块中覆盖此行为。

于 2022-02-04T11:57:42.963 回答