From 57991d19a58903863194043717b2875417a40fe7 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 5 Mar 2015 14:07:52 -0500 Subject: [PATCH] 5261: When redirecting during an AJAX request, send the target URI in a JSON object {"href":"..."} instead of responding 302. This lets us use "redirect_to X" to mean "send the user to page X" regardless of whether the request is an XHR. Without it, client-side code never sees the 302 at all: the browser handles the redirect transparently, and the client-side code typically ends up trying to parse HTML content as JSON. --- apps/workbench/app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index b52591bc0c..0a13fa6b60 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -267,6 +267,14 @@ class ApplicationController < ActionController::Base end end + def redirect_to uri, *args + if request.xhr? + render json: {href: uri} + else + super + end + end + def choose params[:limit] ||= 40 respond_to do |f| -- 2.30.2