ruby-on-rails - PayPal Express 退货配置产生找不到没有 ID 的订单
问题描述
我正在处理 PayPal 快速集成并成功连接到 PayPal 并付款,但在返回时我得到:
ActiveRecord::RecordNotFound in CheckoutController#success
Couldn't find Order without an ID
我的控制器中的操作是:
def place_order
@order = Order.new(params[:order])
@order.customer_ip = request.remote_ip
populate_order
if @order.save
checkout_paypal
else
render :action => 'index'
end
end
def success
@page_title = 'Thank You!'
@order = Order.find(params[:order])
@order.express_payer_id = params[:PayerID]
@order.save
end
private
def checkout_paypal
paypal_response = ::GATEWAY.setup_purchase(
(@order.total * 100).round, # paypal amount is in cents
:ip => request.remote_ip,
:return_url => checkout_success_url(@order),
:cancel_return_url => checkout_error_url(@order)
)
@order.express_token = paypal_response.token
@order.save
redirect_to ::GATEWAY.redirect_url_for(paypal_response.token) and return
end
路线是:
match '/checkout/place_order', :to => 'checkout#place_order'
match '/checkout/success', :to => 'checkout#success'
match '/checkout/error', :to => 'checkout#error'
解决方案
解决方案是将路线更改为:
match '/checkout/success/:id', :to => 'checkout#success', :as => :checkout_success
现在 return_url 工作。
我以前尝试match '/checkout/success/:id', :to => 'checkout#success'
过,但只有:as => :checkout_success
解决了问题。
推荐阅读
- html - 使用 PUG 在多个 HTML 元素上拆分多行文本
- apache - 为什么我的虚拟主机指向第一个虚拟主机?
- android - NotifyItemMoved 在不同的 ViewTypes 之间不起作用
- google-sheets - Google Sheet API v4 是否会在计算(非循环)完成之前获得最终结果?
- gtk3 - 如何让 Gtk.Box 填满所有可用空间?
- sql-server - 迁移 MS Access 2013 数据库以更好地在家工作解决方案
- r - 如何使用 R 计算泊松分布
- android - Android java.lang.ClassNotFoundException:找不到类
- azure-cognitive-search - Azure 搜索:日文搜索片假名和平假名
- r - 具有自定义月顺序的ggplot累积线图