2011-03-11 6 views
2

내 Rails 나머지 응용 프로그램이 json을 기본 출력 형식으로 사용하고 싶습니다. 또한 html 형식을 제거하고 싶습니다. 어떤 제안? 감사합니다RoR 응답 출력 유형

답변

2

예, 할 수 있습니다. 컨트롤러에서

,

respond_to do |format| 
    #format.html # show.html.erb 
    #format.xml { render :xml => @post } 
    format.json { render :json => @post } 
end 

또는 자바 스크립트

respond_to do |format| format.js { render :json { :only => :name}.to_json end 

then you just access your action with ".js" in the end 

로 처리 할 수는 respond_to 블록을 사용하지 않고 JSON에서이

format.any(:xml, :html, :json) { render :json => @post } 
+0

방법을 만드는 기본 렌더링 같은 시도? – Fivell

+0

번째 글이 업데이트되었습니다. – Ashish