After updating to Rails 5.0, I'm getting the following error:
"AbstractController::DoubleRenderError in RegistrationsController#create
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 "reditect_to(...) and return"."
This is my code, which worked before my update:
def create
# save record
if params[:stuff].nil?
respond_to do |format|
format.js
end
else
redirect_to root_path
end
end
I've tried a lot of different syntaxes, for example:
redirect_to(root_path) and return
redirect_to(root_path)
return
return and redirect_to(root_path)
return redirect_to(root_path)
But everything returns the same error. Anyone know the proper syntax?
redirect_to
orrender
in your action? Give this a try:return redirect_to(root_path)
. – Gerryredirect_to
orrender
is present, i will also suggest usingbyebug
to locate where your code is calling that second render. – Gerry