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.
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|