我正在升级我的rails和spree到Rails 4.2和Spree 3.1
我在purchase!
模型
Payment
方法
这是方法在spree中的方式
module Spree
class Payment < Spree::Base
module Processing
def purchase!
started_processing!
gateway_action(source, :purchase, :complete)
end
end
end
end
这就是它在rails 3.2
中被覆盖的方式(直到现在才开始工作)
Spree::Payment::Processing.class_eval do
def purchase!
started_processing!
if source.class == Spree::PurchaseOrder
gateway_action(source, :authorize, :pend)
else
gateway_action(source, :purchase, :complete)
end
end
end
但是现在我收到了Rails 4.2和Spree 3.1的以下错误
/home/deepak/workspace/Project/app/models/spree/payment/processing_decorator.rb:2:in `<module:Spree>': superclass mismatch for class Payment (TypeError)
from /home/deepak/workspace/Project/app/models/spree/payment/processing_decorator.rb:1:in `<top (required)>'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:68:in `load'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
from /home/deepak/workspace/Project/config/application.rb:16:in `block (2 levels) in <class:Application>'
from /home/deepak/workspace/Project/config/application.rb:15:in `glob'
from /home/deepak/workspace/Project/config/application.rb:15:in `block in <class:Application>'
答案 0 :(得分:1)
# /initializers/spree_overrides.rb
module Spree
class Payment < Spree::Base
module Processing
def purchase!
started_processing!
if source.class == Spree::PurchaseOrder
gateway_action(source, :authorize, :pend)
else
gateway_action(source, :purchase, :complete)
end
end
end
end
end
在初始化程序中使用它将覆盖Spree中定义的原始方法。