Rails: Reset rendering/redirecting state

682 views Asked by At

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.

1

There are 1 answers

2
Nerdman On

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