вторник, мая 30, 2006

Acts As Authenticated and Ajax

I've been using AAA-based authentication system and got problems with session expiry. When session is expired action from protected page should redirect to login page. But this doesn't work right if the action is called by Ajax.

The solution is to do the redirect with RJS if it is Ajax request.

Though I don't plan to handle redirects in Ajax request other then to do them, I've changed ActionController::Base.redirect_to to produce RJS redirect for Ajax requests:


def redirect_to(options = {}, *params)
if request.xhr?
render :update do |page|
page.redirect_to url_for(options, *params)
end
else
super
end
end

Комментариев нет: