Rails で実行されている Backbone.js アプリがあり、更新時にオブジェクトを返したいと考えています。json リクエストに応答しない次のコントローラーがあります。
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/withの目的を無効にします。
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)
私はとても混乱しています。