2011-08-04 4 views
2

난 항상 다음과 같은 오류 얻을 : 그것은 ID가 nil을 두 번째로 첫 번째가 아닌 경우,인 AbstractController :: DoubleRenderError 3

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".):

오류가 발생을 ...

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 

외부 리디렉션이 문제가되지 않기 때문에이 리디렉션에서 문제가 발생하지 않습니다. 심지어 디버거이 같은 시간에 리디렉션 ...

어떤 도움에 감사드립니다 ... 마르쿠스

답변

3

이 도우미 함수의 어떤 종류보다는 컨트롤러 동작처럼 보이는이 없습니다. 어떤 경우에는 한 번의 동작에서 calc_next 번을 두 번 호출하거나 동일한 동작의 다른 곳에서 render/redirect_to 번으로 전화를 걸 수도 있습니다. renderredirect_to을 기억하지 않으면 컨트롤러가 즉시 반환됩니다.

제어 경로가 calc_next을 호출 할 수 있는지 확인하고 다른 곳 (calc_next으로 두 번째 호출)에서 render 또는 redirect_to으로 전화하십시오.

진행중인 컨트롤러 작업을 게시하면 더 잘 수행 할 수 있습니다.

+0

쿨, 감사를 반환, 당신이 나에게 정확한 권리 힌트는 next_next() 함수는 리디렉션을했다 준 반환을 이미 통합 된 행동 ... – Markus

0

렌더링 또는 리디렉션 할 수있는 before_filter이 있습니까?

0

또한 두 가지 옵션이 있습니다

리디렉션 ... 그리고 렌더링 ... 그리고

관련 문제