0

以下是我的booking模型中定义的状态。

第一状态

aasm :booking_state,namespace: :booking_state, skip_validation_on_save: true, :whiny_transitions => false do
    state :pending, initial: true
    state :some_other_states
end

第二状态

  aasm :payment_state,namespace: :payment_state, skip_validation_on_save: true, :whiny_transitions => false do
    state :pending, initial: true
    state :some_other_states
end

现在,如果我这样做booking.aasm(:booking_state).current_state,它会返回正确的state名称。

但如果我这样做booking.aasm(:booking_state).pending?,它会返回下面error而不是布尔值。

`NoMethodError: undefined method `pending?' for #<AASM::InstanceBase:0x005611e58e4cf0>`  

这里可能是什么问题?我知道我是否只使用one state每个模型这有效。multiple states但在使用每个模型时不起作用。

4

1 回答 1

3

aasm 的主分支声明方法,例如"#{namespace}_#{state}?"指定命名空间时。

也就是说,booking.booking_state_pending?会工作。

于 2017-10-25T09:15:34.280 回答