2011-01-13 6 views
0

두 개의 사용자 인터페이스가있는 응용 프로그램이 있습니다.Rails3 및 Respond_with 문제

첫 번째 사용자는 일반 사용자 용이고 두 번째 사용자는 iphone 사용자 용입니다.

respond_to 대신 respond_with 선언을 사용하려면 컨트롤러 내에서 코드를 리팩토링 할 때까지 모든 것이 잘 동작하고있었습니다.

응용 프로그램이 여전히 html 인터페이스 (: format => : html)에서는 작동하지만 iphone 인터페이스 (: format => : iphone)에서는 작동하지 않습니다.

iphone에서 다음 작업 (: 색인, : 신규, : 편집, : 표시)을 수행하면 작동합니다.

하지만 할 때 (: create, : update, : destroy) 템플릿을 찾을 수 없다는 오류가 발생합니다 (예 : create.iphone.haml). 내 컨트롤러에서

나는

respond_to :html, :iphone 

그리고 예를 들어, 편집 및 업데이트 작업이

def edit 
    @refund = Refund.find(params[:id]) 
    respond_with(@refund) 
    end 
    def update 
    @refund = Refund.find(params[:id]) 
    if @refund.update_attributes(params[:refund]) 
     flash[:notice] = 'Refund was successfully updated.' 
    end 
    respond_with(@refund, :location => project_refunds_path(@project)) 
    end 

사실, 내가 좋아하는 것 같습니다으로 처리되어 아이폰 형식 : HTML입니다 ... doc에 지정된대로 to_format 메서드를 호출하면 안됩니다.

답변

1

자신에 의해 그것을 해결.

는 그냥 초기화 파일에이를 추가해야

ActionController::Responder.class_eval do 
    alias :to_iphone :to_html 
end 
0

은 당신이 할 경우에는 어떻게 :

respond_with(@refund, :location => project_refunds_path(@project)) do |format| 
    format.iphone { whatever you had here before refactoring } 
end 
+0

네, 그것은 해결책이 될 수 있습니다. 그러나 그것은 나를 위해 마르기에 충분하지 않다. 아이폰과 html 형식은 그들이 응답해야하는 방식과 동일합니다. 가능한 경우 더 나은 방법을 찾고 있습니다. 어쨌든 Thx;) – Arkan