Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Created March 14, 2012 20:19
Show Gist options
  • Select an option

  • Save Bodacious/2039224 to your computer and use it in GitHub Desktop.

Select an option

Save Bodacious/2039224 to your computer and use it in GitHub Desktop.
Responding to a JSON PUT/DELETE request with JSON
class MyController < ApplicationController
def update
if resource.update_attributes(params[:resource])
render json: resource, status: :ok # status is :ok by default so feel free to remove this option
else
render json: { errors: resource.errors }, status: :unprocessable_entity
end
end
def destroy
resource.destroy
# what would you show here? Empty json?
render json: {}
end
private
def resource
@resource ||= Resouce.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment