1
我有一個運行在Rails上的Backbone.js應用程序,當我更新時我想返回對象。我有以下控制器不響應我的JSON請求。Rails respond_with不...響應
class EventsController < ApplicationController
respond_to :html, :json
def update
@event = Event.find(params[:id])
@event.update_attributes(params[:event])
respond_with @event
end
end
它顯示在控制檯以下:
(1.9ms) COMMIT
Completed 204 No Content in 12ms (ActiveRecord: 0.0ms)
以下,然而工作...但它違背了respond_to代碼的目的/使用。
class EventsController < ApplicationController
respond_to :html, :json
def update
@event = Event.find(params[:id])
respond_to do |format|
if @event.update_attributes(params[:event])
format.json {render json: @event}
end
end
end
end
這顯示在控制檯以下:
(0.1ms) COMMIT
**A bunch of Select Queries**
Completed 200 OK in 27ms (Views: 10.2ms | ActiveRecord: 5.0ms)
我很困惑。
你是什麼意思與「沒有迴應」它必須發送的東西,或請求超時? – Arjan 2013-05-02 12:15:03
對不起,剛剛在兩種情況下保存時添加了控制檯日誌。破碎的方式說204沒有內容,並且正在工作(但看起來不正確和冗長)的是200 OK。然而,它們都是承諾的。 – jake 2013-05-02 16:14:26