Braintree 结帐在部署后给出错误 Braintree::ConfigurationError
Braintree checkout gives error `Braintree::ConfigurationError` after deploy
嗨,我昨天使用 Passenger/Capistrano 和 Nginx 服务器将应用程序部署到 VPS。
一切都运行很顺利,除了我在订单页面上输入checkout
按钮。
然后应用程序崩溃,在 production.log
中有此错误行 Braintree::ConfigurationError (Braintree::Configuration.merchant_id needs to be set):
app/controllers/orders_controller.rb:22:in 'new'
问题是Merchiant_id
设置好了,我完全迷路了。
在部署之前,我将 Sandbox
API 键更改为 application.yml
中的 Production
API 键。我正在使用 figaro
来隐藏 API keys
。
当我 运行 在 localhost
部署之前,一切正常。
我一遍又一遍地浏览了 Braintree 指南。我找不到任何错误。
我是不是漏掉了什么?
这是 orders_controller.rb
错误的来源。
class OrdersController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:new, :create]
before_action :set_order, only: [:show, :edit, :destroy]
def index
@orders = Order.all?
end
def new
@images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
@random_no = rand(5)
@random_image = @images[@random_no]
if @cart.product_items.empty?
redirect_to root_url, notice: 'Your Cart is Empty'
return
end
@order = Order.new
@client_token = Braintree::ClientToken.generate #this is line 22 were the error is
end
def create
@order = Order.new(order_params)
if @order.save
charge
if @result.success?
@order.add_product_items_from_cart(@cart)
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
OrderNotifier.received(@order).deliver
redirect_to root_url, notice: 'Thank You for Your Order'
else
flash[:error] = 'Please Check Your Cart'
redirect_to root_url, alert: @result.message
@order.destroy
end
else
@client_token = Braintree::ClientToken.generate
render :new
end
end
def show
end
def destroy
@order.destroy
redirect_to root_url, notice: 'Order deleted'
end
private
def set_order
@order = Order.find(params[:id])
end
def order_params
params.require(:order).permit(:name, :email, :address, :city, :country)
end
def charge
@result = Braintree::Transaction.sale(
amount: @cart.total_price_usd,
payment_method_nonce: params[:payment_method_nonce] )
end
end
我遇到过一次类似的问题,基本上都是一样的错误。
在我的案例中,我为解决这个问题所做的是在`deploy.rb``
中将 config/application.yml
添加到 set :linked_files
所以这条线看起来像这样set :linked_files, %w{ config/application.yml}
然后在再次部署之前,您必须在服务器上创建 application.yml
。很可能在 ~/YOURAPP/shared/config$
而你 copy/paste 从你机器上的 application.yml
到 ~/YOURAPP/shared/config/application.yml
的代码
我几乎可以打赌添加这个会解决你的问题
嗨,我昨天使用 Passenger/Capistrano 和 Nginx 服务器将应用程序部署到 VPS。
一切都运行很顺利,除了我在订单页面上输入checkout
按钮。
然后应用程序崩溃,在 production.log
中有此错误行 Braintree::ConfigurationError (Braintree::Configuration.merchant_id needs to be set):
app/controllers/orders_controller.rb:22:in 'new'
问题是Merchiant_id
设置好了,我完全迷路了。
在部署之前,我将 Sandbox
API 键更改为 application.yml
中的 Production
API 键。我正在使用 figaro
来隐藏 API keys
。
当我 运行 在 localhost
部署之前,一切正常。
我一遍又一遍地浏览了 Braintree 指南。我找不到任何错误。
我是不是漏掉了什么?
这是 orders_controller.rb
错误的来源。
class OrdersController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:new, :create]
before_action :set_order, only: [:show, :edit, :destroy]
def index
@orders = Order.all?
end
def new
@images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
@random_no = rand(5)
@random_image = @images[@random_no]
if @cart.product_items.empty?
redirect_to root_url, notice: 'Your Cart is Empty'
return
end
@order = Order.new
@client_token = Braintree::ClientToken.generate #this is line 22 were the error is
end
def create
@order = Order.new(order_params)
if @order.save
charge
if @result.success?
@order.add_product_items_from_cart(@cart)
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
OrderNotifier.received(@order).deliver
redirect_to root_url, notice: 'Thank You for Your Order'
else
flash[:error] = 'Please Check Your Cart'
redirect_to root_url, alert: @result.message
@order.destroy
end
else
@client_token = Braintree::ClientToken.generate
render :new
end
end
def show
end
def destroy
@order.destroy
redirect_to root_url, notice: 'Order deleted'
end
private
def set_order
@order = Order.find(params[:id])
end
def order_params
params.require(:order).permit(:name, :email, :address, :city, :country)
end
def charge
@result = Braintree::Transaction.sale(
amount: @cart.total_price_usd,
payment_method_nonce: params[:payment_method_nonce] )
end
end
我遇到过一次类似的问题,基本上都是一样的错误。
在我的案例中,我为解决这个问题所做的是在`deploy.rb``
中将config/application.yml
添加到 set :linked_files
所以这条线看起来像这样set :linked_files, %w{ config/application.yml}
然后在再次部署之前,您必须在服务器上创建 application.yml
。很可能在 ~/YOURAPP/shared/config$
而你 copy/paste 从你机器上的 application.yml
到 ~/YOURAPP/shared/config/application.yml
我几乎可以打赌添加这个会解决你的问题