簡體   English   中英

nil:NilClass的未定義方法“ association_class”

[英]undefined method `association_class' for nil:NilClass

我正在使用Spree 2.1並嘗試添加新的支付網關,但是此錯誤更為籠統,因此Spree本身在這里並不那么重要。

在向Spree::PaymentMethodsource )類添加一些模塊后,我遇到了該錯誤( undefined method 'association_class' for nil:NilClass ):

大禮包/ payment_method_decorator.rb

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

Spree::Core::CalculatedAdjustments

Spree::Gateway 來源

不幸的是,現在Spree::PaymentMethodsource )中斷了一點,即:

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

有誰知道為什么會這樣以及如何解決?

實際上,我已經有了一個答案(經過幾個小時的努力),但是也許有人會給出適當解釋的更好答案。 也許答案很明顯,但這不是我的事,我也找不到與之相關的任何東西,因此希望其他具有類似RoR知識水平的人不必再花幾個小時。

因此答案是:

從上面的鏈接中可以看到, Spree::GatewaySpree::PaymentMethod繼承而我的自定義付款方式從Spree::Gateway類繼承-類似:

module Spree class Gateway::CustomMethod < Gateway end end

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

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

從那時起它一直在工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM