Railsのログイン機能で使用しています
session[:return_to] = request.request_uri
次に、私が使用するロギング機能で:
redirect_to session[:return_to]
これは、AJAXでパーシャルをレンダリングする場合を除いて正常に機能します。何が起こるかというと、request.uriはAJAXリクエスト用であり、期待どおりに機能しなくなります。
私がこれを回避する方法を知っていますか?
ありがとう、
タム
Railsのログイン機能で使用しています
session[:return_to] = request.request_uri
次に、私が使用するロギング機能で:
redirect_to session[:return_to]
これは、AJAXでパーシャルをレンダリングする場合を除いて正常に機能します。何が起こるかというと、request.uriはAJAXリクエスト用であり、期待どおりに機能しなくなります。
私がこれを回避する方法を知っていますか?
ありがとう、
タム
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]
This may do what you want:
redirect_to :back