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 回答