views:

350

answers:

2

Hi,

In my Rails logging in functionality I use

session[:return_to] = request.request_uri

and then in the logging functionality I use:

redirect_to session[:return_to]

Which works fine except when I render a partial with AJAX. What happens is that the request.uri is for the AJAX request which screws up and doesn't render what's expected.

You know how I can go around this?

Thanks,

Tam

A: 

This may do what you want:

redirect_to :back
nfm
That didn't work! it actually kept the user at the login page
Tam
A: 

request.request_uri will indeed be for the AJAX URI. The only solution I've found is to make your AJAX requests (or at least, the ones that may cause a redirect to the login page) include the URI of the whole page, e.g.

form_remote_for ... do |f|
    hidden_field_tag :this_page, request.request_uri
    # only works if this view itself is not loaded over AJAX!

or for a more universal approach:

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

Combine either of these with

# in the login action
session[:return_to] = params[:this_page]
Chris Boyle