I need to redirect to a route in the controller after executing a Jquey
I have the following jquery:
$(document).on("change", "parte_id", function () {
$.ajax({
url: "/actualizar_parte",
type: "GET",
data: {
"id": $('#parte_id').val()
},
dataType: "json"
});
});
And in the controller I have the following code:
def actualizar_parte
return redirect_to parte_actual_path(params[:id])
end
It enters the action in the controller, it stays in a short loop (I see it in the puma log), it ends, but it doesn't redirect to the new address.
Redirects (responses with status code 302) are interpreted by the client (in this case, your browser) to call the new url. For example when you click on a link and the response from the server comes with a 302, it is the browser that makes the request to the new url.
You didn't explain more details of your logic, but for your case, where you're using
$.ajax
, which comes from an external library and your browser wouldn't have to interpret the responses it receives, I think your best option is to handle the redirect from the same xhr call :