4

I have an exception handler (registered with rescue_from) which sometimes causes Double Render errors because the real action has already rendered/redirected before the exception is thrown.

To prevent this exception, I'm looking for the modern equivalent of erase_results. It cleared any rendering/redirecting activity in the current request. Not sure why it was deprecated as it seems useful. Anyway, I've tried to reconstruct it by digging into the original source, but some of the detail has changed too, so it would be a hack and I'd rather do it cleanly.

mahemoff
  • 44,526
  • 36
  • 160
  • 222

1 Answers1

1

Rails uses controller#response_body to decide if the request is already rendered or redirected. Just set response_body to nil to avoid this error. Note: arguably better way is to prevent multiple rendering or redirecting at first place.

See: #render

Nerdman
  • 21
  • 7
  • OK I'll try to test it later. Btw it's not really practical to prevent this as both redirects and exceptions are natural events and this just happens whenever both of those happen. – mahemoff Feb 10 '14 at 09:02
  • 1
    This runs into complications with newer versions of Rails: https://github.com/rails/rails/issues/25106 – Jake Shorty Jul 24 '18 at 23:54