[英]Rails, Devise - send user back after submitting form
當用戶將產品添加到購物車中時,登錄不是強制性的。但是,當他進入創建的購物車並點擊“結帳”時,我會檢查他是否已登錄:
<%=
link_to_if(current_user.nil?, "Checkout", new_user_session_path) do
link_to( "Checkout", new_order_path, method: :get)
end
%>
因此,如果未登錄,我將重定向到new_user_session_path。 問題是登錄后他將被重定向到index_path。 我希望他被重定向回他的購物車。 與登錄相同。
我正在使用Devise,所以我應該生成Devise控制器並從那里開始嗎? 應該怎么做?
注意:我正在使用當前購物車的模塊:
module CurrentCart
private
def set_cart
@cart = Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
@cart = Cart.create
session[:cart_id] = @cart.id
end
end
我認為這段代碼將幫助您:
class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource)
#place your route here
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.