I always get the following error:
AbstractController::DoubleRenderError (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”.):
The error happens, when it id is nil the first, but not the second time…
def calc_next
id = next()
if id.nil?
id = next_next()
if id.nil?
render :layout => false, :format => :js
else
redirect_to :action => "view", :id => id, :format => :js
end
else
redirect_to :action => "view", :id => id, :format => :js
end
end
I don’t see the problem in this redirection, as the outer one is fine. Even with the debugger there are not two redirections at the same time…
Any help is appreciated…
Markus
This looks like some kind of helper function rather than a Controller action. In which case you’re probably calling
calc_nexttwice in one action, orrender/redirect_tofrom somewhere else in the same action. Remember thatrenderandredirect_todon’t immediately cause the Controller to return.Check whether your control path can both call
calc_nextand callrenderorredirect_tofrom somewhere else (or from a second call intocalc_next).If you post the controller action you’re going through, we may be able to help better.