What should I render when destroying a record? What should I render when destroying a record? ruby-on-rails ruby-on-rails

What should I render when destroying a record?


A success status of 204 (no content) appears appropriate. As implied by 204, there must not be a response body, which can be achieved with render :nothing, status: :no_content or a bit more catchy:

def destroy  item.destroy  head :no_contentend

Edit: render :nothing has been deprecated and been removed since Rails 5.1. Instead you could use render body: nil, status: :no_content.


For a delete request, http status code 200 or 204 implies resource deleted successfully.

9.7 DELETE

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

So you can either return the object with 200 status code or empty response with 204 status code