Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created December 30, 2013 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abuiles/8189324 to your computer and use it in GitHub Desktop.
Save abuiles/8189324 to your computer and use it in GitHub Desktop.
class Api::ClientsController < ApplicationController
before_action :set_client, only: [:show, :edit, :update, :destroy]
respond_to :json
# GET /clients
def index
@clients = Client.all
respond_with @clients
end
# GET /clients/1
def show
respond_with @client
end
# POST /clients
def create
@client = Client.new(client_params)
if @client.save
respond_with(@client, status: :created, location: api_client_url(@client))
else
render json: @client.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /clients/1
def update
if @client.update(client_params)
head :no_content
else
render json: @client.erros, status: :unprocessable_entity
end
end
# DELETE /clients/1
def destroy
@client.destroy
head :no_content
end
private
def set_client
@client = Client.find(params[:id])
end
def client_params
params.require(:client).permit(:first_name, :last_name, :phone, :email)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment