Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Ember Data expect in response to deleting a record?

I'm using Ember Data with the RESTful adapter with a rails backend.

When I delete a record from Ember record.deleteRecord(); record.save() the DELETE request goes to the server and the model is deleted, but this error is printed to the javascript console:

Extract requested, but no data given for App.ThisModel. This may cause weird problems.

The response from the server was just render json: true, so I changed it to render json: deleted_model which renders the json for the deleted record.

That got rid of the previous error, but now the deleted record is recreated in Ember.

What does Ember expect in the response?

like image 418
everett1992 Avatar asked Dec 18 '13 02:12

everett1992


2 Answers

You should send back a 200 with an empty valid json response {}, any data returned is applied to the record as if they were attributes.

http://emberjs.jsbin.com/OxIDiVU/215/edit

Additionally you can send back a 204 with no response.

http://emberjs.jsbin.com/OxIDiVU/214/edit

like image 61
Kingpin2k Avatar answered Oct 07 '22 00:10

Kingpin2k


jQuery 1.9 no longer treats a response of 200 for a JSON request as a success. Your server should now be returning a 204 response for DELETE requests with empty response body.

For a rails server, you can do something like this:     

def destroy
  @something.destroy!
  head :no_content
end
like image 25
Sapan Diwakar Avatar answered Oct 07 '22 00:10

Sapan Diwakar