Backbone model.destroy() invoking error callback function even when it works fine?

后端 未结 5 1256
不知归路
不知归路 2021-02-05 01:01

I have a Backbone.js model that I\'m trying to destroy when the user clicks a link in the model\'s view. The view is something like this (pseudocode because it\'s implemented in

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 01:51

    @David Tuite comment:

    "Ok I figured it out. It seems that Backbone expects the JSON response to be a JSON serialization of the record that was destroyed. However, Rails controller generators only return head :ok by default. I changed my JSON response to be render json: @listing_save where @listing_save is the record I just destroyed and it registers a success."

    FYI - when you're doing a destroy, you don't need to return the full json for the destroyed model. you can return an empty json hash and it will work just fine. the only time you need to return the json for the model is on a save / update.

提交回复
热议问题