Created
December 30, 2013 22:28
-
-
Save abuiles/8189324 to your computer and use it in GitHub Desktop.
This file contains 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 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