我需要从控制器checkout_controller.rb覆盖方法rescue_from_spree_gateway_error
我的网关正在返回这个:
Gateway Error --- !ruby/object:ActiveMerchant::Billing::Response params: success: false order_status: message: Autoriza��o negada amount: order: transaction: message: Autoriza��o negada success: false test: false authorization: fraud_review: avs_result: code: message: street_match: postal_match: cvv_result: code: message:
这是我的覆盖,在/app/controllers/checkout_controller_decorator.rb
module Spree
CheckoutController.class_eval do
def rescue_from_spree_gateway_error(error)
puts "==========================================="
flash[:error] = error.message
render :edit
end
end
end
我已经添加了,puts
所以我可以在控制台上看到它,但它没有打印出来。
我还在puts
方法声明上方添加了另一个,当我启动服务器时它会打印出来:
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
!!!!!THIS IS ABOVE THE METHOD!!!!! [2013-09-05 16:33:31] INFO WEBrick 1.3.1 [2013-09-05 16:33:31] INFO ruby 1.9.3 (2013-06-27) [x86_64-linux] [2013-09-05 16:33:31] INFO WEBrick::HTTPServer#start: pid=21635 port=3000
因此,它向我显示该类已加载,但从未调用该方法,就像上面返回的错误ActiveMerchant::Billing::Response
不是网关错误一样。
有这一checkout_controller
行在发生时调用该方法GatewayError
:
rescue_from Spree::Core::GatewayError, :with => :rescue_from_spree_gateway_error