1

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)

私はとても混乱しています。

4

1 に答える 1

0

私はいくつかの問題を抱えていました。どうやらそのように振る舞うことになっているようです。Rails github でこの問題を参照してください: https://github.com/rails/rails/issues/9069

于 2014-04-22T18:01:37.217 に答える