Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Api::ClientsController < ApplicationController
- skip_before_action :verify_authenticity_token
- def index
- render json: Client.all
- end
- def show
- client = Client.find(params[:id])
- render json: client
- end
- def create
- client = Client.new(client_params)
- if client.save!
- head 200
- else
- head 500
- end
- end
- private
- def client_params
- params.require("client").permit(:name, :email, :password, :password_confirmation)
- end
- end
- curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"oi", "email":"oi2@gmail.com","password":"123456", "password_confirmation":"123456"}' http://localhost:3000/api/clients
- Processing by Api::ClientsController#create as JSON
- Parameters: {"name"=>"oi", "email"=>"oi2@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "client"=>{"name"=>"oi", "email"=>"oi2@gmail.com"}}
- (0.1ms) begin transaction
- ↳ app/controllers/api/clients_controller.rb:12
- Client Exists (0.3ms) SELECT 1 AS one FROM "clients" WHERE "clients"."email" = ? LIMIT ? [["email", "oi2@gmail.com"], ["LIMIT", 1]]
- ↳ app/controllers/api/clients_controller.rb:12
- (0.1ms) rollback transaction
- ↳ app/controllers/api/clients_controller.rb:12
- Completed 422 Unprocessable Entity in 7ms (ActiveRecord: 0.4ms)
- ActiveRecord::RecordInvalid (Validation failed: Password can't be blank):
- app/controllers/api/clients_controller.rb:12:in `create'
Add Comment
Please, Sign In to add comment