Skip to content

Instantly share code, notes, and snippets.

@glesage
Created March 31, 2014 21:23
Show Gist options
  • Save glesage/9902677 to your computer and use it in GitHub Desktop.
Save glesage/9902677 to your computer and use it in GitHub Desktop.
class DataController < ApplicationController
# GET /data
# GET /data.json
def index
@data = Datum.all
render json: @data
end
# GET /data/1
# GET /data/1.json
def show
@datum = Datum.find(params[:id])
render json: @datum
end
# POST /data
# POST /data.json
def create
@datum = Datum.new(params[:datum])
if @datum.save
render json: @datum, status: :created, location: @datum
else
render json: @datum.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /data/1
# PATCH/PUT /data/1.json
def update
@datum = Datum.find(params[:id])
if @datum.update(params[:datum])
head :no_content
else
render json: @datum.errors, status: :unprocessable_entity
end
end
# DELETE /data/1
# DELETE /data/1.json
def destroy
@datum = Datum.find(params[:id])
@datum.destroy
head :no_content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment