我有一个模型:
class CashPayment < ActiveRecord::Base
.....
**enum status: [:processing, :paid, :invalid,:refund]**
end
在这里,我已经宣布cash_payment的无效状态。但它给我的错误如下:
*** ArgumentError Exception: You tried to define an enum named "status" on the model "CashPayment", but this will generate a instance method "invalid?", which is already defined by Active Record
答案 0 :(得分:0)
invalid?
已由ActiveRecord
定义。
您的枚举status
还包含:invalid
,其中提供的方法为invalid?
现在生成两个invalid?
方法时存在冲突。
尝试为:invalid
提供另一个名称,例如:invalid_rec
enum status: [:processing, :paid, :invalid_rec,:refund]