【问题标题】:Braintree checkout gives error `Braintree::ConfigurationError` after deployBraintree 结帐在部署后给出错误“Braintree::ConfigurationError”
【发布时间】:2016-09-30 05:36:35
【问题描述】:

您好,我昨天使用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 中的ProductionAPI 密钥。我正在使用figaro 隐藏API keys

当我在 localhostbefore deploy 上运行此程序时,一切正常。

我一遍又一遍地浏览了 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

【问题讨论】:

    标签: ruby-on-rails ruby nginx e-commerce braintree


    【解决方案1】:

    我曾经遇到过类似的问题,基本上是同样的错误。

    在我的情况下,我为解决这个问题所做的是将config/application.yml 添加到`deploy.rb` 中的set :linked_files

    所以这条线看起来像这样set :linked_files, %w{ config/application.yml}

    那么在您再次部署之前,您必须在服务器上创建application.yml。很可能在~/YOURAPP/shared/config$

    然后将代码从机器上的application.yml 复制/粘贴到~/YOURAPP/shared/config/application.yml

    我几乎可以打赌,添加它会解决您的问题

    【讨论】:

    • No....我收到一个新错误,服务器上缺少 application.yml ......我想我必须在服务器上创建它
    • 天哪,非常感谢这解决了我的错误,现在一切正常:)
    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2018-06-30
    • 2017-12-10
    • 2017-08-11
    • 2014-10-16
    相关资源
    最近更新 更多