2011-02-05 3 views
2

원격으로 (ajax를 통해) 레코드를 업데이트하려고하는데 직렬화 된 레코드를 포함하는 응답을 얻지 만 계속 xhr.responseText = {}를 얻고 있습니다. 업데이트 된 레코드의 일련 화 된 버전을 받고 싶습니다. 성공 이벤트Rails respond_with json이 잘못 작동 함

: 여기

내보기 양식 ...

=semantic_form_for theme, :html => {'data-type' => 'json', :id => :theme_display_type_form, :remote => true} do |form| 
    -form.inputs do 
     =form.input :display_type 

처리하는 컨트롤러 ...

respond_to :html, :json 

... other actions... 

def update 
    flash[:success] = "Theme was successfully updated" if theme.update_attributes params[:theme] 
    respond_with(theme) 
end 

다음 응답이 rails.js 아약스에 의해 체포된다

$('#theme_display_type_form').bind('ajax:success', function(evt, data, status, xhr){ 
    var responseObject = $.parseJSON(xhr.responseText); 
    alert(xhr.responseText); // = {} 
    alert(responseObject); // = null 
}); 

나는 뭔가를 놓쳐 야합니다. 아무도 내가 잘못하고있는 것을 알려 줄 수 있습니까?


편집 내가 제대로 작동 내 컨트롤러에 이전 respond_to 방법을 사용하는 등 'respond_with'와 관련된 문제가 될 수 있습니다처럼 보이는

...

def update 
    flash[:success] = "Theme was successfully updated" if theme.update_attributes params[:theme] 
    respond_to do |format| 
     format.json { render :json => theme } 
    end 
end 

누구나 respond_with가 제대로 작동하지 않는 이유는 누구나 알 수 있습니까?


답변에 등대 게시에 따라

https://rails.lighthouseapp.com/projects/8994/tickets/5199-respond_with-returns-on-put-and-delete-verb

가 이미 보유하고있는 객체를 갖고 있기 때문에 업데이트가 어떤 객체를 반환하지 않습니다 것이 정상입니다 ..

답변

0

respond_with에는 문제가 있지만 respond_to는 올바르게 작동합니다.

POST (작성)에서 확인합니다. 때로는 respond_with 작품처럼 보입니다 ...

관련 문제