I'm working with Spree 2.1 and trying to add new payment gateway, but this error is more generic so Spree itself is not-so-important here.
I have encountered that error (undefined method 'association_class' for nil:NilClass
) after adding some module to Spree::PaymentMethod
(source) class:
spree/payment_method_decorator.rb
Spree::PaymentMethod.class_eval do
include Spree::Core::CalculatedAdjustments
end
(Spree::Core::CalculatedAdjustments
source)
(Spree::Gateway
source)
Unfortunately, now Spree::PaymentMethod
(source) breaks a little, i.e:
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
Does anyone know why this happens and how to fix it?
In fact I already have an answer (after few hours of struggle), but maybe someone will give a better one with proper explanation. Maybe the answer is quite obvious, but it wasn't for me and I couldn't find anything related on SO so hopefully someone else with similar level of RoR knowledge won't have to spend another few hours on that.