Bypass XHR redirect by overriding redirect_to

A lot of calls in Rails end in a redirect_to, and this is really an
unnecessary round trip in the case of XHR calls. This might sound
crazy, but why not just handle the redirect on the server? I realize
in some cases a redirect will probably be better if the redirected
resource is cached, but that’s not always the case.

Is there any advice/prior art on doing such a thing, and is it
sensible to do it? I’m thinking the best way is to monkey-patch the
default redirect_to method.

Hi Michael,

On Thu, Dec 22, 2011 at 6:33 PM, Michael M. [email protected]
wrote:

A lot of calls in Rails end in a redirect_to, and this is really an
unnecessary round trip in the case of XHR calls. This might sound
crazy, but why not just handle the redirect on the server? I realize
in some cases a redirect will probably be better if the redirected
resource is cached, but that’s not always the case.

Is there any advice/prior art on doing such a thing, and is it
sensible to do it? I’m thinking the best way is to monkey-patch the
default redirect_to method.

The RJS library provides a server-side redirect_to for use with
prototype.js. You might want to start there.

HTH,
Bill

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs