Ruby on rails 未定义的方法'association#u class';零级:零级

Ruby on rails 未定义的方法'association#u class';零级:零级,ruby-on-rails,associations,spree,class-eval,Ruby On Rails,Associations,Spree,Class Eval,我正在使用Spree 2.1并尝试添加新的支付网关,但这个错误更为常见,因此Spree本身在这里并不重要 在将一些模块添加到Spree::PaymentMethod()类中后,我遇到了该错误(未定义nil:NilClass的方法“association\u class”): spree/payment\u method\u decorator.rb Spree::PaymentMethod.class_eval do include Spree::Core::CalculatedAdjust

我正在使用Spree 2.1并尝试添加新的支付网关,但这个错误更为常见,因此Spree本身在这里并不重要

在将一些模块添加到
Spree::PaymentMethod
()类中后,我遇到了该错误(
未定义nil:NilClass的方法“association\u class”):

spree/payment\u method\u decorator.rb

Spree::PaymentMethod.class_eval do
  include Spree::Core::CalculatedAdjustments
end
Spree::Core::CalculatedAdjustments

Spree::Gateway

不幸的是,现在的
Spree::PaymentMethod
()有点中断,即:

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
n=Spree::PaymentMethod.first
=> #
n、 拯救
=>nil:NilClass的未定义方法“association\u class”
n、 计算器
=>nil:NilClass的未定义方法“association\u class”
有人知道为什么会发生这种情况以及如何解决吗

事实上,我已经有了一个答案(经过几个小时的努力),但也许有人会给出一个更好的解释。也许答案很明显,但不是我,我也找不到任何与此相关的信息,所以希望其他具有类似RoR知识水平的人不必再花几个小时在这方面。

因此答案是:

正如上面的链接所示,
Spree::Gateway
继承自
Spree::PaymentMethod
,我的自定义支付方法继承自
Spree::Gateway
类-类似于:

模块狂欢
类网关::CustomMethod<网关
结束
结束

我所要做的就是在
Spree::Gateway
中包含
Spree::Core::CalculatedAdjustments

Spree::Gateway.class\u eval do
包括Spree::Core::CalculatedAdjustments
结束


从那时起它就开始工作了。

你做了什么来修复它?你能回答你自己的问题吗?我也遇到了同样的问题。@maikel很抱歉反应太晚,我不得不为那个项目挖出我的旧笔记本电脑;)我已经把答案贴在下面了。