我正在尝试找出执行以下操作的最佳方法(我能想到几种方法,但我想知道处理它的最佳方法是什么):
用户正在整理货物,然后单击“发送”链接,该链接将他发送到该/shipments/:id/confirm
页面。该confirm
操作检查用户是否完成了ShippingAddress
; 如果没有,它会将他发送到ShippingAddress#new
. (如果他这样做了,它会渲染confirm
页面。
我希望用户能够完成ShippingAddress#new
页面,提交它,然后被重定向回/shipments/:id/confirm
. 我怎样才能做到这一点?如何在不执行类似操作的情况下将其传递:id
到页面?或者这是最好的方法吗?ShippingAddress#new
redirect_to new_shipping_address_path(shipment_id: @shipment.id)
Shipment#confirm
class ShipmentsController < ApplicationController
def confirm
@shipment = Shipment.where(id: params[:id]).first
unless current_user.has_a_shipping_address?
# Trying to avoid having a query string, but right now would do the below:
# in reality, there's a bit more logic in my controller, handling the cases
# where i should redirect to the CardProfiles instead, or where I don't pass the
# shipment_id, and instead use the default shipment.
redirect_to new_shipping_address_path(shipment_id: @shipment.id)
end
end
end
class ShippingAddressesController < ApplicationController
def new
@shipment = Shipment.where(id: params[:shipment_id]).first
end
def create
@shipment = Shipment.where(id: params[:shipment_id]).first
redirect_to confirm_shipment_path(@shipment)
end
end
【其实在收货地址之后还有一个CardProfiles#new
页面需要填写】。