Conditional respond_to doesn't do redirect

I have such a code in my "create" method:

respond_to do |format|
  if user.save()
    format.html {redirect_to(:action => "show")}
  else
    format.js
  end
end

So if save() is successful I want full redirect to a different page. If
not successful then no redirect, just show user an ajax message about
the error on the same page.

My form is with 'data-remote="true"'.

And my "create.js.erb" is simple:
  document.getElementById("warn").innerHTML = "<p>Error</p>";

Save() works fine but I get no redirection. The same page stays without
change. And if save() is impossible then format.js works fine. But why
redirection doesn't work?

If this is responding to an AJAX request, what do you think would be
the result of redirecting the AJAX request?

tamouse mailing lists wrote in post #1105944:

If this is responding to an AJAX request, what do you think would be
the result of redirecting the AJAX request?

Yes, you're right :slight_smile:
window.location = ... works