在我的Rails登錄的功能我用問題的request.request_uri從AJAX部分轉發時 - Rails的
session[:return_to] = request.request_uri
,然後在日誌記錄功能使用:
redirect_to session[:return_to]
除了工作正常當我使用AJAX呈現部分內容時。會發生什麼情況是request.uri是針對AJAX請求的,並且無法呈現預期結果。
你知道我該如何解決這個問題嗎?
感謝,
擔
在我的Rails登錄的功能我用問題的request.request_uri從AJAX部分轉發時 - Rails的
session[:return_to] = request.request_uri
,然後在日誌記錄功能使用:
redirect_to session[:return_to]
除了工作正常當我使用AJAX呈現部分內容時。會發生什麼情況是request.uri是針對AJAX請求的,並且無法呈現預期結果。
你知道我該如何解決這個問題嗎?
感謝,
擔
這可能會做你想要什麼:
redirect_to :back
request.request_uri
的確會爲AJAX URI。我發現的唯一解決方案是使您的AJAX請求(或者至少可能導致重定向到登錄頁面的請求)包含整個頁面的URI,例如,
form_remote_for ... do |f|
hidden_field_tag :this_page, request.request_uri
# only works if this view itself is not loaded over AJAX!
或一個更通用的方法:
form_remote_for :html => {:onsubmit => '$("this_page").value = window.location'}, ... do |f|
hidden_field_tag :this_page, request.request_uri
# non-JS clients just end up with the value given here
結合任一有
# in the login action
session[:return_to] = params[:this_page]
那沒有工作!它實際上保持用戶在登錄頁面 – Tam 2009-10-05 17:46:16