私は次のことを行うための最良の方法を見つけようとしています(私が考えることができるいくつかの方法がありますが、それを処理するための最良の方法が何であるかを知りたいです):
ユーザーが荷物をまとめてから、[送信]リンクをクリックすると、/shipments/:id/confirmページに移動します。アクションは、ユーザーが完了したconfirmかどうかを確認しますShippingAddress。そうでない場合は、彼をに送信しますShippingAddress#new。(彼がそうする場合、それはページをレンダリングしconfirmます。
ユーザーがShippingAddress#newページを完成させて送信してから、にリダイレクトできるようにしたいと思います/shipments/:id/confirm。どうやってやるの?アクションのようなことをせず:idにページにを渡すにはどうすればよいですか?それともそれを行うための最良の方法ですか?ShippingAddress#newredirect_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、配送先住所の後に記入する必要のあるページもあります]。