Created
March 14, 2012 20:19
-
-
Save Bodacious/2039224 to your computer and use it in GitHub Desktop.
Responding to a JSON PUT/DELETE request with JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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