我能够使用硬编码金额成功结帐,即:
def checkout
nonce = params["payment_method_nonce"]
if current_user.braintree_id?
customer = Braintree::Customer.find(current_user.braintree_id)
else
@result = Braintree::Customer.create(
email: current_user.email,
payment_method_nonce: params[:payment_method_nonce]
)
customer = result.customer
current_user.update(braintree_id: customer.id)
end
@result = Braintree::Transaction.sale(
amount: **"10.00"**,
payment_method_nonce: nonce
)
if @result.success?
redirect_to root_path, notice: "You have successfully checked out"
else
flash[:alert] = "Something went wrong while processing your transaction"
render :new
end
end
假设我希望 current_user 能够以存储在我的 rails 数据库中的特定“价格”购买我的投资组合的访问权限。有没有办法通过从数据库中的对象属性中提取金额来设置金额,即:“<=@portofolio_item.price>”?我已经尝试了多次,但没有任何运气。我可能做错了什么?