title: AbstractController::DoubleRenderError in rails 3
body: <p>I always get the following error:</p>
  
  <blockquote>
    <p>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".):</p>
  </blockquote>
  
  <p>The error happens, when it id is nil the first, but not the second time...</p>
  
  <pre><code>def calc_next
    id = next()
    if id.nil?
      id = next_next()
      if id.nil?
        render :layout =&gt; false, :format =&gt; :js
      else
        redirect_to :action =&gt; "view", :id =&gt; id, :format =&gt; :js
      end
    else
      redirect_to :action =&gt; "view", :id =&gt; id, :format =&gt; :js
    end
  end
  </code></pre>
  
  <p>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...</p>
  
  <p>Any help is appreciated...
  Markus</p>