0
在鐵軌我得到的錯誤uninitialized constant CartController::EXPRESS_CHECKOUT
而我在調用此方法的控制器CartController
的express_checkout
,我認爲這個問題是在配置/環境/ development.rb文件,因爲我定義未初始化的常量ActiveMerchant
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
login: "<mail>",
password: "<pass>",
signature: "<sig>"
}
::EXPRESS_GATEWAY =
ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
但即使我試圖改變在這個文件中的東西,我無法修復這個錯誤。
這是cart_controller.rb
def express_checkout
response = EXPRESS_GATEWAY.setup_purchase(params[:amount], ip: request.remote_ip, return_url: "http://localhost:8080/checkout_details", cancel_return_url: "http://localhost:8080", currency: "EUR", allow_guest_checkout: true, items: [{name: "Order", description: "Order description", quantity: "1", amount: params[:amount]}]
)
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end
def checkout_details
@token = params[:token]
@payer_id = params[:PayerID]
@details = EXPRESS_GATEWAY.details_for(@token)
end
def purchase
@t = params[:token]
@p = params[:PayerID]
@result = EXPRESS_GATEWAY.purchase(params[:amount], {:token => @t, :payer_id => @p, :currency => "EUR"})
end
的我檢查了寶石activemerchant
的版本,是1.66.0
版本的代碼,所以這種寶石的版本是沒有問題的。 任何人都知道這件事?
您可以將「CartController」的源代碼添加到問題中嗎? – Tobias
完成!讓我知道你是否需要別的東西 – mao95
它看起來像Rails在控制器命名空間中搜索'EXPRESS_GATEWAY'常量。你有沒有嘗試在動作中調用':: EXPRESS_GATEWAY'?否則,它看起來像常量沒有被初始化。我建議你在'config/initializers'目錄下創建一個初始化文件並在那裏初始化它。 – Tobias