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

这可能会做你想做的事:

redirect_to :back
于 2009-10-05T07:38:19.740 回答