1

Railsのログイン機能で使用しています

session[:return_to] = request.request_uri

次に、私が使用するロギング機能で:

redirect_to session[:return_to]

これは、AJAXでパーシャルをレンダリングする場合を除いて正常に機能します。何が起こるかというと、request.uriはAJAXリクエスト用であり、期待どおりに機能しなくなります。

私がこれを回避する方法を知っていますか?

ありがとう、

タム

4

2 に答える 2

0

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]
于 2010-06-03T15:35:10.333 に答える
0

This may do what you want:

redirect_to :back
于 2009-10-05T07:38:19.740 に答える