我正在使用 Spree 2.1 并尝试添加新的支付网关,但这个错误更普遍,所以 Spree 本身在这里并不那么重要。
undefined method 'association_class' for nil:NilClass
在将一些模块添加到Spree::PaymentMethod
(源)类后,我遇到了该错误( ):
spree/payment_method_decorator.rb
Spree::PaymentMethod.class_eval do
include Spree::Core::CalculatedAdjustments
end
(Spree::Core::CalculatedAdjustments
来源)
(Spree::Gateway
来源)
不幸的是,现在Spree::PaymentMethod
(source)有点中断,即:
n = Spree::PaymentMethod.first
=> #<Spree::Gateway::Bogus id: 1, (...)>
n.save
=> undefined method 'association_class' for nil:NilClass
n.calculator
=> undefined method 'association_class' for nil:NilClass
有谁知道为什么会发生这种情况以及如何解决它?
事实上,我已经有了答案(经过几个小时的努力),但也许有人会给出一个更好的答案,并给出适当的解释。也许答案很明显,但它不适合我,我找不到任何与 SO 相关的东西,所以希望其他具有类似 RoR 知识水平的人不必再花几个小时在这上面。