2011-02-05 37 views
2

私はリモートで(ajax経由で)レコードを更新しようとしていますが、シリアル化されたレコードを含むレスポンスを取得しようとしていますが、xhr.responseText = {}私は更新されたレコードのシリアル化されたバージョンを受け取りたいと思います。Railsが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のAJAXによってキャッチされ、コントローラ:成功イベント

$('#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' で問題を有するものであってもよいように見えEDIT

...

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がうまく動作しない理由を知っていますか?


ANSWER上の灯台の投稿につきとして

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

あなたがすでに所有しているオブジェクトを持っているので、UPDATEが、何のオブジェクトを返すないこと、通常の..です

答えて

0

私はrespond_withに問題がありますが、respond_toは正しく動作します。

POST(作成)に表示されます。それは時々respond_with仕事のようだ...

関連する問題