2014-02-24 3 views
1

안녕하세요, 저는 xml 데이터를 서버에 게시하고 응답에 따라 페이지를 리디렉션하고 싶습니다. 내 컨트롤러에 대한 내 action 및 send_xml 메서드가 있습니다.DoubleRenderError after Net :: HTTP.post_form

루비 버전 : 2.0.0-p247

레일 버전 :

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

내 생각 : 나는이 작업을 실행하려고하면 3.2.17

def new 
    @sales = current_user.sales.new 
    respond_with(@sales) 
end 

def fail 
    flash[:error] = 'Canceled' 
    render :new 
end 

def success 
    result = send_xml(params) 
    if result['Response'] == 'Approved' 
    flash[:success] = 'Approved' 
    redirect_to(approved_path) 
    return 
    else 
    flash[:error] = 'Failed' 
    redirect_to(failed_path) 
    return 
    end 
end 
private 
def send_xml(params) 
    request = "DATA=<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?><myData>Foo</myData>" 
    uri = URI.parse('http://foobar.com') 
    xml = render xml: request 
    response = Net::HTTP.post_form(uri, xml) 
    response = Hash.from_xml(response.body) 
    response['myResponse'] 
end 

내가 좋아하는 오류 NET :: HTTP.post_form 메서드는 렌더링 또는 리디렉션을 트리거하고 이로 인해이 오류가 발생합니다.

이 오류를 제거하려면 어떻게해야합니까? 당신이, 당신이 #success에서 호출 #send_xml에서 render xml: request을 요구하고있다, 따라서 당신이 (메시지도 표시로)을 제외하고 결과 renderredirect를 호출하기 때문에이 문제가 발생 도움

답변

1

에 대한

감사합니다.

+0

감사하지만 여전히 같은 오류가 발생합니다. – htkaya

+0

컨트롤러의 전체 코드를 게시 할 수 있습니까? – Agis

+0

오류 메시지와 렌더링을 반환하는 새롭고 실패한 동작이 있습니다. 새 메시지를 편집 중입니다. – htkaya

관련 문제