[Rails] AbstractController::DoubleRenderError

Tadashi Shigeoka ·  Wed, November 23, 2011

In Ruby on Rails 3.1, I encountered an AbstractController::DoubleRenderError.

■ Error details

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

You get an error when multiple render processes are executed like this:

render :index
render :show # Error occurs here due to duplicate render

If you want to terminate execution after a render process, you need to write return.

render :index and return # Processing ends here
render :show # This is not processed

That’s all from the Gemba.

【References】

ruby on rails - AbstractController::DoubleRenderError that shouldn’t be - Stack Overflow